{"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":"# 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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\n\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-08-29T13:31:25.246313Z","iopub.execute_input":"2023-08-29T13:31:25.246783Z","iopub.status.idle":"2023-08-29T13:31:25.258585Z","shell.execute_reply.started":"2023-08-29T13:31:25.246748Z","shell.execute_reply":"2023-08-29T13:31:25.257570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n%matplotlib inline ","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:25.260520Z","iopub.execute_input":"2023-08-29T13:31:25.261591Z","iopub.status.idle":"2023-08-29T13:31:25.270746Z","shell.execute_reply.started":"2023-08-29T13:31:25.261552Z","shell.execute_reply":"2023-08-29T13:31:25.269353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:25.272704Z","iopub.execute_input":"2023-08-29T13:31:25.273357Z","iopub.status.idle":"2023-08-29T13:31:30.151534Z","shell.execute_reply.started":"2023-08-29T13:31:25.273318Z","shell.execute_reply":"2023-08-29T13:31:30.149781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:30.153313Z","iopub.execute_input":"2023-08-29T13:31:30.153828Z","iopub.status.idle":"2023-08-29T13:31:30.189482Z","shell.execute_reply.started":"2023-08-29T13:31:30.153792Z","shell.execute_reply":"2023-08-29T13:31:30.188380Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.tail()","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:30.192932Z","iopub.execute_input":"2023-08-29T13:31:30.193461Z","iopub.status.idle":"2023-08-29T13:31:30.216014Z","shell.execute_reply.started":"2023-08-29T13:31:30.193412Z","shell.execute_reply":"2023-08-29T13:31:30.214510Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.describe()","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:30.217531Z","iopub.execute_input":"2023-08-29T13:31:30.217996Z","iopub.status.idle":"2023-08-29T13:31:33.092756Z","shell.execute_reply.started":"2023-08-29T13:31:30.217956Z","shell.execute_reply":"2023-08-29T13:31:33.091336Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.094269Z","iopub.execute_input":"2023-08-29T13:31:33.094685Z","iopub.status.idle":"2023-08-29T13:31:33.102111Z","shell.execute_reply.started":"2023-08-29T13:31:33.094619Z","shell.execute_reply":"2023-08-29T13:31:33.100738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = data.iloc[:, 1:].values\nX.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.104127Z","iopub.execute_input":"2023-08-29T13:31:33.104546Z","iopub.status.idle":"2023-08-29T13:31:33.118984Z","shell.execute_reply.started":"2023-08-29T13:31:33.104508Z","shell.execute_reply":"2023-08-29T13:31:33.117359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = data.iloc[:, 0].values","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.121154Z","iopub.execute_input":"2023-08-29T13:31:33.121604Z","iopub.status.idle":"2023-08-29T13:31:33.129707Z","shell.execute_reply.started":"2023-08-29T13:31:33.121565Z","shell.execute_reply":"2023-08-29T13:31:33.128598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.135782Z","iopub.execute_input":"2023-08-29T13:31:33.136281Z","iopub.status.idle":"2023-08-29T13:31:33.144747Z","shell.execute_reply.started":"2023-08-29T13:31:33.136244Z","shell.execute_reply":"2023-08-29T13:31:33.143679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=9)","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.147779Z","iopub.execute_input":"2023-08-29T13:31:33.148591Z","iopub.status.idle":"2023-08-29T13:31:33.923259Z","shell.execute_reply.started":"2023-08-29T13:31:33.148551Z","shell.execute_reply":"2023-08-29T13:31:33.922217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.924754Z","iopub.execute_input":"2023-08-29T13:31:33.925161Z","iopub.status.idle":"2023-08-29T13:31:33.934161Z","shell.execute_reply.started":"2023-08-29T13:31:33.925126Z","shell.execute_reply":"2023-08-29T13:31:33.932256Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.936322Z","iopub.execute_input":"2023-08-29T13:31:33.936721Z","iopub.status.idle":"2023-08-29T13:31:33.947340Z","shell.execute_reply.started":"2023-08-29T13:31:33.936686Z","shell.execute_reply":"2023-08-29T13:31:33.946183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier\nclf = DecisionTreeClassifier()","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.948734Z","iopub.execute_input":"2023-08-29T13:31:33.949109Z","iopub.status.idle":"2023-08-29T13:31:33.959677Z","shell.execute_reply.started":"2023-08-29T13:31:33.949077Z","shell.execute_reply":"2023-08-29T13:31:33.958302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:33.961261Z","iopub.execute_input":"2023-08-29T13:31:33.961837Z","iopub.status.idle":"2023-08-29T13:31:47.017132Z","shell.execute_reply.started":"2023-08-29T13:31:33.961791Z","shell.execute_reply":"2023-08-29T13:31:47.015840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = clf.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:47.019049Z","iopub.execute_input":"2023-08-29T13:31:47.019573Z","iopub.status.idle":"2023-08-29T13:31:47.045092Z","shell.execute_reply.started":"2023-08-29T13:31:47.019529Z","shell.execute_reply":"2023-08-29T13:31:47.043586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:47.049624Z","iopub.execute_input":"2023-08-29T13:31:47.050065Z","iopub.status.idle":"2023-08-29T13:31:47.059411Z","shell.execute_reply.started":"2023-08-29T13:31:47.050033Z","shell.execute_reply":"2023-08-29T13:31:47.057735Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test[100]","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:47.060939Z","iopub.execute_input":"2023-08-29T13:31:47.061384Z","iopub.status.idle":"2023-08-29T13:31:47.073909Z","shell.execute_reply.started":"2023-08-29T13:31:47.061321Z","shell.execute_reply":"2023-08-29T13:31:47.072697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred[100]","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:47.075367Z","iopub.execute_input":"2023-08-29T13:31:47.075814Z","iopub.status.idle":"2023-08-29T13:31:47.089228Z","shell.execute_reply.started":"2023-08-29T13:31:47.075778Z","shell.execute_reply":"2023-08-29T13:31:47.087874Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(X_test[100].reshape(28,28))\nclf.predict(X_test[100].reshape(1, 784))","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:31:47.092082Z","iopub.execute_input":"2023-08-29T13:31:47.093281Z","iopub.status.idle":"2023-08-29T13:31:47.426909Z","shell.execute_reply.started":"2023-08-29T13:31:47.093226Z","shell.execute_reply":"2023-08-29T13:31:47.425340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score, confusion_matrix\nac = accuracy_score(y_test, y_pred)\nprint('Test set Accuracy: {:.2f}'.format(ac))","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:34:30.224971Z","iopub.execute_input":"2023-08-29T13:34:30.225452Z","iopub.status.idle":"2023-08-29T13:34:30.234698Z","shell.execute_reply.started":"2023-08-29T13:34:30.225414Z","shell.execute_reply":"2023-08-29T13:34:30.233195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cm = confusion_matrix(y_test, y_pred)\nprint(cm)","metadata":{"execution":{"iopub.status.busy":"2023-08-29T13:36:27.847565Z","iopub.execute_input":"2023-08-29T13:36:27.848003Z","iopub.status.idle":"2023-08-29T13:36:27.859294Z","shell.execute_reply.started":"2023-08-29T13:36:27.847971Z","shell.execute_reply":"2023-08-29T13:36:27.857521Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}