{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.metrics import classification_report\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.ensemble import AdaBoostClassifier\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.model_selection import train_test_split\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train=pd.read_csv(\"../input/train.csv\")\ntest=pd.read_csv(\"../input/test.csv\")\ntrain.head()\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c8593bbbc48be36c74a8c7a3f4ad89b1ceb61604"},"cell_type":"code","source":"train1,test1 = train_test_split(train,test_size=0.3,random_state=100)\n\ntrain1_x = train1.drop('label',axis = 1)\ntrain1_y = train1['label']\ntest1_x =  test1.drop('label',axis = 1)\ntest1_y = test1['label']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"96c8de1bb13187a5b19289b61a8f68a75a2b00c5"},"cell_type":"code","source":"model_dt = DecisionTreeClassifier(random_state=100,max_depth=10)\nmodel_dt.fit(train1_x,train1_y)\npred = model_dt.predict(test1_x)\naccuracy_dt=accuracy_score(pred,test1_y)\nprint(accuracy_dt)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7d2823681da8e6cf4eb46f97dbf2014d23b47568"},"cell_type":"code","source":"model_rf = RandomForestClassifier(random_state=100,n_estimators=300)\nmodel_rf.fit(train1_x,train1_y)\npred_rf = model_rf.predict(test1_x)\naccuracy_rf=accuracy_score(pred_rf,test1_y)\nprint(accuracy_rf)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c7f0342e76a1801107855207da662065a8ced753"},"cell_type":"code","source":"model_ada = AdaBoostClassifier(random_state=100)\nmodel_ada.fit(train1_x,train1_y)\npred_ada =model_ada.predict(test1_x)\naccuracy_ada = accuracy_score(pred_ada,test1_y)\nprint(accuracy_ada)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b516a9a7a8c1ccd6d50179db9993b8d267ff1811"},"cell_type":"code","source":"final = pd.DataFrame({'Decision Tree':[accuracy_dt],\n                     'Random Forest':[accuracy_rf],\n                     'AdaBoost':[accuracy_ada]})\nfinal","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e60b4f872c3dea754215a06a6db1a1c4e44a1f2a"},"cell_type":"code","source":"train_x=train.drop(\"label\",axis=1)\ntrain_y=train[\"label\"]\nmodel=RandomForestClassifier(random_state=100,n_estimators=1000)\nmodel.fit(train_x,train_y)\ntest_predict= model.predict(test)\ndt_predict=pd.DataFrame({\"Label\":test_predict})\ndt_predict[\"ImageId\"]=test.index+1\ndt_predict[[\"ImageId\",\"Label\"]].to_csv(\"prediction.csv\",index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dd862f6ad01df49bf44a850e17495007a22ddfc7"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}