{"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)\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\")\n#train.head()\n#test=pd.read_csv(\"../input/test.csv\")\n#test.head()\nsample_submission=pd.read_csv(\"../input/train.csv\")\n#sample_submission.head()\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\nfrom sklearn.metrics import accuracy_score","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"33ac96815bc88d42a8b8d15bfdc4e2a10c74e996"},"cell_type":"code","source":"train,validate = train_test_split(train,test_size = 0.3, random_state =100)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c8082454180b96d1505cd44766be5b0400403053"},"cell_type":"code","source":"## Decision Tree \ntrain1_y = train['label']\ntrain1_x = train.drop('label', axis=1)\ntest1_y = validate['label']\ntest1_x = validate.drop('label', axis=1)\n\nmodel = DecisionTreeClassifier(random_state=100)\nmodel.fit(train1_x,train1_y)\n\ntest_pred = model.predict(test1_x)\nprint(accuracy_score(test1_y, test_pred))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dc190aa79fdec3cc0d83e1533433df339cf44dd3"},"cell_type":"code","source":"## Random Forest\ntrain1_y = train['label']\ntrain1_x = train.drop('label', axis=1)\ntest1_y = validate['label']\ntest1_x = validate.drop('label', axis=1)\n\nmodel_rf = RandomForestClassifier(random_state=100,n_estimators = 1000)\nmodel_rf.fit(train1_x, train1_y)\n\ntest_pred_rf = model_rf.predict(test1_x)\nprint(accuracy_score(test1_y, test_pred_rf))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b9d4eb9001f69ee0eb52f6a0b6134a96e19d579d"},"cell_type":"code","source":"## Adaptive Boost\ntrain1_y = train['label']\ntrain1_x = train.drop('label', axis=1)\ntest1_y = validate['label']\ntest1_x = validate.drop('label', axis=1)\n\nmodel = AdaBoostClassifier(random_state=100)\nmodel.fit(train1_x,train1_y)\n\ntest_pred_Ab = model.predict(test1_x)\nprint(accuracy_score(test1_y, test_pred_Ab))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a9ab41f24cd7a3bb0245ac2fdcc6aa5ec55f7e95"},"cell_type":"code","source":"## K Nearest Neighbors\ntrain1_y = train['label']\ntrain1_x = train.drop('label', axis=1)\ntest1_y = validate['label']\ntest1_x = validate.drop('label', axis=1)\n\nmodel = KNeighborsClassifier(n_neighbors=5)\nmodel.fit(train1_x,train1_y)\n\ntest_pred_knn = model.predict(test1_x)\nprint(accuracy_score(test1_y, test_pred_knn))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"044183e9bd61a2ecfe970203774692e80cf78acc"},"cell_type":"code","source":"test_pred = model_rf.predict(test)\ndf_test_pred = pd.DataFrame(test_pred, columns=['Label'])\ndf_test_pred['ImageId'] = test.index + 1\ndf_test_pred[['ImageId','Label']].to_csv('Submission.csv', index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"261c6dc56d6e8c383630a6344dc961dddc0770ac"},"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}