{"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# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"33400be45c6ddb87ab72dd5b496face17c5ee3a3"},"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix \n# Importing Decission Tree Classifier\nfrom sklearn.tree import DecisionTreeClassifier\n# Importing Random Forest classifier\nfrom sklearn.ensemble import RandomForestClassifier\n# Importing Adaboost classifier\nfrom sklearn.ensemble import AdaBoostClassifier\n# Importing KNN classifier\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.metrics import accuracy_score","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\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5ce2647e23854de96591da98977ffbb47f5aba9c"},"cell_type":"code","source":"# splitting the train data into test train sets \ntrain_t,test_t = train_test_split(train,test_size = 0.3, random_state =100)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bd76af3d430e4b7c1ee0ec41d54f067893ab9c1a"},"cell_type":"code","source":"# defining or test_x ,test_y ,train_x and train_y\ntrain_y = train_t['label']\ntest_y = test_t['label']\ntrain_x = train_t.drop('label', axis=1)\ntest_x = test_t.drop('label', axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"781728b551481e2389582040b030a7b8750b154f"},"cell_type":"code","source":"#Decission Tree\nmodel_dtc = DecisionTreeClassifier(random_state=100)   \nmodel_dtc.fit(train_x,train_y)\n\ntest_pred_dtc = model_dtc.predict(test_x)\nacc = accuracy_score(test_y, test_pred_dtc)\nprint(acc)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"59e676c5bc8c3bb5e79ad1dfd985837d8588543c","scrolled":true},"cell_type":"code","source":"#Random Forest\nmodel_rf = RandomForestClassifier(random_state=100, n_estimators=1000)\nmodel_rf.fit(train_x,train_y)\n\ntest_pred_rf = model_rf.predict(test_x)\nacc1 = accuracy_score(test_y, test_pred_rf)\nprint(acc1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6d0bd293b2395f7122af1b302cd3f50affe62d94"},"cell_type":"code","source":"#Adaboost\nmodel_ada = AdaBoostClassifier(random_state=100, n_estimators=1000)\nmodel_ada.fit(train_x,train_y)\n\ntest_pred_ada = model_ada.predict(test_x)\nacc2 = accuracy_score(test_y, test_pred_ada)\nprint(acc2)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"506cf8ede51f8fd2e3b58342e661e6e49ef54783"},"cell_type":"code","source":"#KNN\n#model_knn = KNeighborsClassifier(n_neighbors=5)\n#model_knn.fit(train_x,train_y)\n\n#test_pred_knn = model_knn.predict(test_x)\n#acc3 = accuracy_score(test_y, test_pred_knn)\n#print(acc3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9046e7685d1ea9c3217dbdf66186cbd6ad7bc76b"},"cell_type":"code","source":"#Applying RandomForest as its accuracy is better\ntest_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)\ndf_test_pred['ImageId'].shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bb0bd4b8bf2084dea6708fc81ec5e33ee66bec19"},"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}