{"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-10-02T15:03:56.795050Z","iopub.execute_input":"2021-10-02T15:03:56.795370Z","iopub.status.idle":"2021-10-02T15:03:56.822169Z","shell.execute_reply.started":"2021-10-02T15:03:56.795294Z","shell.execute_reply":"2021-10-02T15:03:56.821330Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:04:18.363244Z","iopub.execute_input":"2021-10-02T15:04:18.364147Z","iopub.status.idle":"2021-10-02T15:04:21.913903Z","shell.execute_reply.started":"2021-10-02T15:04:18.364101Z","shell.execute_reply":"2021-10-02T15:04:21.913243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:04:21.915159Z","iopub.execute_input":"2021-10-02T15:04:21.915725Z","iopub.status.idle":"2021-10-02T15:04:21.940102Z","shell.execute_reply.started":"2021-10-02T15:04:21.915691Z","shell.execute_reply":"2021-10-02T15:04:21.939598Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.imshow(df.iloc[3,1:].values.reshape(28,28))","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:09:45.935178Z","iopub.execute_input":"2021-10-02T15:09:45.935999Z","iopub.status.idle":"2021-10-02T15:09:46.142619Z","shell.execute_reply.started":"2021-10-02T15:09:45.935961Z","shell.execute_reply":"2021-10-02T15:09:46.141743Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = df.iloc[:,1:]\ny = df.iloc[:,0]","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:10:45.254651Z","iopub.execute_input":"2021-10-02T15:10:45.254978Z","iopub.status.idle":"2021-10-02T15:10:45.261882Z","shell.execute_reply.started":"2021-10-02T15:10:45.254941Z","shell.execute_reply":"2021-10-02T15:10:45.259953Z"},"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)","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:11:25.650789Z","iopub.execute_input":"2021-10-02T15:11:25.651303Z","iopub.status.idle":"2021-10-02T15:11:26.832794Z","shell.execute_reply.started":"2021-10-02T15:11:25.651257Z","shell.execute_reply":"2021-10-02T15:11:26.832034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:11:34.059007Z","iopub.execute_input":"2021-10-02T15:11:34.059298Z","iopub.status.idle":"2021-10-02T15:11:34.065208Z","shell.execute_reply.started":"2021-10-02T15:11:34.059271Z","shell.execute_reply":"2021-10-02T15:11:34.064390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:11:40.152993Z","iopub.execute_input":"2021-10-02T15:11:40.153272Z","iopub.status.idle":"2021-10-02T15:11:40.159676Z","shell.execute_reply.started":"2021-10-02T15:11:40.153243Z","shell.execute_reply":"2021-10-02T15:11:40.158741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test.shape","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:11:51.384028Z","iopub.execute_input":"2021-10-02T15:11:51.384347Z","iopub.status.idle":"2021-10-02T15:11:51.390106Z","shell.execute_reply.started":"2021-10-02T15:11:51.384316Z","shell.execute_reply":"2021-10-02T15:11:51.389135Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.tree import DecisionTreeClassifier\nclf = DecisionTreeClassifier()","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:12:14.888852Z","iopub.execute_input":"2021-10-02T15:12:14.889104Z","iopub.status.idle":"2021-10-02T15:12:14.893378Z","shell.execute_reply.started":"2021-10-02T15:12:14.889079Z","shell.execute_reply":"2021-10-02T15:12:14.892289Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:12:23.551354Z","iopub.execute_input":"2021-10-02T15:12:23.551656Z","iopub.status.idle":"2021-10-02T15:12:33.846830Z","shell.execute_reply.started":"2021-10-02T15:12:23.551623Z","shell.execute_reply":"2021-10-02T15:12:33.846031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:12:52.755997Z","iopub.execute_input":"2021-10-02T15:12:52.756283Z","iopub.status.idle":"2021-10-02T15:12:52.766049Z","shell.execute_reply.started":"2021-10-02T15:12:52.756257Z","shell.execute_reply":"2021-10-02T15:12:52.764362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:12:44.800115Z","iopub.execute_input":"2021-10-02T15:12:44.800391Z","iopub.status.idle":"2021-10-02T15:12:44.822422Z","shell.execute_reply.started":"2021-10-02T15:12:44.800365Z","shell.execute_reply":"2021-10-02T15:12:44.821424Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf.predict(X_test.iloc[4].values.reshape(1,784))","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:14:10.078306Z","iopub.execute_input":"2021-10-02T15:14:10.079173Z","iopub.status.idle":"2021-10-02T15:14:10.085755Z","shell.execute_reply.started":"2021-10-02T15:14:10.079130Z","shell.execute_reply":"2021-10-02T15:14:10.085134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = clf.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:14:29.688803Z","iopub.execute_input":"2021-10-02T15:14:29.689741Z","iopub.status.idle":"2021-10-02T15:14:29.719926Z","shell.execute_reply.started":"2021-10-02T15:14:29.689695Z","shell.execute_reply":"2021-10-02T15:14:29.719158Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:14:31.932862Z","iopub.execute_input":"2021-10-02T15:14:31.933127Z","iopub.status.idle":"2021-10-02T15:14:31.938493Z","shell.execute_reply.started":"2021-10-02T15:14:31.933100Z","shell.execute_reply":"2021-10-02T15:14:31.937672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2021-10-02T15:14:56.342567Z","iopub.execute_input":"2021-10-02T15:14:56.342991Z","iopub.status.idle":"2021-10-02T15:14:56.350224Z","shell.execute_reply.started":"2021-10-02T15:14:56.342948Z","shell.execute_reply":"2021-10-02T15:14:56.349537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}