{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np \nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix\nfrom sklearn.ensemble import GradientBoostingClassifier\nfrom sklearn.neighbors import KNeighborsClassifier\nfrom sklearn.svm import SVC\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-19T05:49:47.349709Z","iopub.execute_input":"2022-07-19T05:49:47.350440Z","iopub.status.idle":"2022-07-19T05:49:48.765392Z","shell.execute_reply.started":"2022-07-19T05:49:47.350324Z","shell.execute_reply":"2022-07-19T05:49:48.763242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv('../input/digit-recognizer/train.csv')\ndf_train","metadata":{"execution":{"iopub.status.busy":"2022-07-19T05:49:48.770419Z","iopub.execute_input":"2022-07-19T05:49:48.772725Z","iopub.status.idle":"2022-07-19T05:49:52.833250Z","shell.execute_reply.started":"2022-07-19T05:49:48.772686Z","shell.execute_reply":"2022-07-19T05:49:52.831166Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(df_train['label'])","metadata":{"execution":{"iopub.status.busy":"2022-07-19T05:49:52.834487Z","iopub.execute_input":"2022-07-19T05:49:52.836262Z","iopub.status.idle":"2022-07-19T05:49:53.093806Z","shell.execute_reply.started":"2022-07-19T05:49:52.836223Z","shell.execute_reply":"2022-07-19T05:49:53.092752Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = df_train.drop(columns=['label'])\ny = df_train['label']","metadata":{"execution":{"iopub.status.busy":"2022-07-19T05:49:53.096072Z","iopub.execute_input":"2022-07-19T05:49:53.096681Z","iopub.status.idle":"2022-07-19T05:49:53.180368Z","shell.execute_reply.started":"2022-07-19T05:49:53.096641Z","shell.execute_reply":"2022-07-19T05:49:53.179379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(x, y, train_size=0.9, shuffle=True, random_state=44)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T05:49:53.181969Z","iopub.execute_input":"2022-07-19T05:49:53.182326Z","iopub.status.idle":"2022-07-19T05:49:53.394583Z","shell.execute_reply.started":"2022-07-19T05:49:53.182291Z","shell.execute_reply":"2022-07-19T05:49:53.393610Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"GBCModel = GradientBoostingClassifier(n_estimators=300,max_depth=8,random_state=44) \nGBCModel.fit(X_train, y_train)\n\nprint('GBCModel Train Score is : ' , GBCModel.score(X_train, y_train))\nprint('GBCModel Test Score is : ' , GBCModel.score(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-19T05:50:06.287044Z","iopub.execute_input":"2022-07-19T05:50:06.287897Z","iopub.status.idle":"2022-07-19T06:11:13.456416Z","shell.execute_reply.started":"2022-07-19T05:50:06.287860Z","shell.execute_reply":"2022-07-19T06:11:13.454453Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_GB = GBCModel.predict(X_test)\nCM_GB = confusion_matrix(y_test, y_pred_GB)\n\nsns.heatmap(CM_GB, center=True)\nplt.show()\n\nprint('Confusion Matrix is\\n', CM_GB)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T06:11:13.457358Z","iopub.status.idle":"2022-07-19T06:11:13.458102Z","shell.execute_reply.started":"2022-07-19T06:11:13.457834Z","shell.execute_reply":"2022-07-19T06:11:13.457857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"KNNClassifierModel = KNeighborsClassifier(n_neighbors= 13,weights ='distance', algorithm='ball_tree')\nKNNClassifierModel.fit(X_train, y_train)\n\nprint('KNNClassifierModel Train Score is : ' , KNNClassifierModel.score(X_train, y_train))\nprint('KNNClassifierModel Test Score is : ' , KNNClassifierModel.score(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-15T22:32:40.200081Z","iopub.execute_input":"2022-07-15T22:32:40.201073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_KNN = KNNClassifierModel.predict(X_test)\nCM_KNN = confusion_matrix(y_test, y_pred_KNN)\n\nsns.heatmap(CM_KNN, center=True)\nplt.show()\n\nprint('Confusion Matrix is\\n', CM_KNN)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SVCModel = SVC(kernel= 'poly', max_iter=500, C=0.1, gamma='auto', random_state=33)\nSVCModel.fit(X_train, y_train)\n\nprint('SVCModel Train Score is : ' , SVCModel.score(X_train, y_train))\nprint('SVCModel Test Score is : ' , SVCModel.score(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-19T06:11:13.460140Z","iopub.status.idle":"2022-07-19T06:11:13.460601Z","shell.execute_reply.started":"2022-07-19T06:11:13.460357Z","shell.execute_reply":"2022-07-19T06:11:13.460378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_SVC = SVCModel.predict(X_test)\nCM_SVC = confusion_matrix(y_test, y_pred_SVC)\n\nsns.heatmap(CM_SVC, center=True)\nplt.show()\n\nprint('Confusion Matrix is\\n', CM_SVC)","metadata":{"execution":{"iopub.status.busy":"2022-07-19T06:11:13.462388Z","iopub.status.idle":"2022-07-19T06:11:13.462859Z","shell.execute_reply.started":"2022-07-19T06:11:13.462624Z","shell.execute_reply":"2022-07-19T06:11:13.462646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import VotingClassifier\nVotingClassifierModel = VotingClassifier(estimators=[('GBCModel',GBCModel),\n                                                     ('KNNModel',KNNClassifierModel),\n                                                     ('SVCModel',SVCModel)],\n                                         voting='hard')\nVotingClassifierModel.fit(X_train, y_train)\nprint('VotingClassifierModel Train Score is : ' , VotingClassifierModel.score(X_train, y_train))\nprint('VotingClassifierModel Test Score is : ' , VotingClassifierModel.score(X_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2022-07-15T20:43:04.459118Z","iopub.execute_input":"2022-07-15T20:43:04.460184Z","iopub.status.idle":"2022-07-15T21:18:49.372041Z","shell.execute_reply.started":"2022-07-15T20:43:04.460137Z","shell.execute_reply":"2022-07-15T21:18:49.371078Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_V = VotingClassifierModel.predict(X_test)\nCM_V = confusion_matrix(y_test, y_pred_V)\nsns.heatmap(CM_V, center=True)\nplt.show()\nprint('Confusion Matrix is\\n', CM_V)","metadata":{"execution":{"iopub.status.busy":"2022-07-15T21:18:49.373498Z","iopub.execute_input":"2022-07-15T21:18:49.374018Z","iopub.status.idle":"2022-07-15T21:22:14.576482Z","shell.execute_reply.started":"2022-07-15T21:18:49.373982Z","shell.execute_reply":"2022-07-15T21:22:14.575499Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv('../input/digit-recognizer/test.csv')\ndf_test","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:37:35.815282Z","iopub.execute_input":"2022-07-10T19:37:35.816069Z","iopub.status.idle":"2022-07-10T19:37:37.619600Z","shell.execute_reply.started":"2022-07-10T19:37:35.816026Z","shell.execute_reply":"2022-07-10T19:37:37.618732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_df_test = df_test.iloc[:]","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:37:37.622712Z","iopub.execute_input":"2022-07-10T19:37:37.623166Z","iopub.status.idle":"2022-07-10T19:37:37.627393Z","shell.execute_reply.started":"2022-07-10T19:37:37.623140Z","shell.execute_reply":"2022-07-10T19:37:37.626225Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred_gbc = GBCModel.predict(x_df_test)\ny_pred_knn = KNNClassifierModel.predict(x_df_test)\ny_pred_svc = SVCModel.predict(x_df_test)","metadata":{"execution":{"iopub.status.busy":"2022-07-10T19:37:38.445859Z","iopub.execute_input":"2022-07-10T19:37:38.446584Z","iopub.status.idle":"2022-07-10T19:57:41.779587Z","shell.execute_reply.started":"2022-07-10T19:37:38.446544Z","shell.execute_reply":"2022-07-10T19:57:41.778403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"'''submission1 = pd.DataFrame([])\nsubmission1.index.name ='ImageId'\nsubmission.index+=1\nsubmission1['Label'] = y_pred_svc\nsubmission1.to_csv('submission_svc8.csv', header=True)'''","metadata":{"execution":{"iopub.status.busy":"2022-07-10T02:30:29.473124Z","iopub.execute_input":"2022-07-10T02:30:29.47456Z","iopub.status.idle":"2022-07-10T02:30:29.534011Z","shell.execute_reply.started":"2022-07-10T02:30:29.474513Z","shell.execute_reply":"2022-07-10T02:30:29.533078Z"},"trusted":true},"execution_count":null,"outputs":[]}]}