{"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-18T14:29:59.156493Z","iopub.execute_input":"2021-10-18T14:29:59.156802Z","iopub.status.idle":"2021-10-18T14:29:59.193177Z","shell.execute_reply.started":"2021-10-18T14:29:59.156713Z","shell.execute_reply":"2021-10-18T14:29:59.192111Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest_data = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"execution":{"iopub.status.busy":"2021-10-18T14:30:41.490686Z","iopub.execute_input":"2021-10-18T14:30:41.491162Z","iopub.status.idle":"2021-10-18T14:30:47.361794Z","shell.execute_reply.started":"2021-10-18T14:30:41.491113Z","shell.execute_reply":"2021-10-18T14:30:47.360879Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-18T14:30:51.861719Z","iopub.execute_input":"2021-10-18T14:30:51.861988Z","iopub.status.idle":"2021-10-18T14:30:51.890508Z","shell.execute_reply.started":"2021-10-18T14:30:51.861959Z","shell.execute_reply":"2021-10-18T14:30:51.889676Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-18T14:30:54.699121Z","iopub.execute_input":"2021-10-18T14:30:54.699902Z","iopub.status.idle":"2021-10-18T14:30:54.718595Z","shell.execute_reply.started":"2021-10-18T14:30:54.699845Z","shell.execute_reply":"2021-10-18T14:30:54.717778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=train_data['label']\ny.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-18T14:30:57.107865Z","iopub.execute_input":"2021-10-18T14:30:57.108186Z","iopub.status.idle":"2021-10-18T14:30:57.117993Z","shell.execute_reply.started":"2021-10-18T14:30:57.108149Z","shell.execute_reply":"2021-10-18T14:30:57.117223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X=train_data.drop('label', axis=1)\nX.head()","metadata":{"execution":{"iopub.status.busy":"2021-10-18T14:30:59.256052Z","iopub.execute_input":"2021-10-18T14:30:59.256550Z","iopub.status.idle":"2021-10-18T14:30:59.393261Z","shell.execute_reply.started":"2021-10-18T14:30:59.256494Z","shell.execute_reply":"2021-10-18T14:30:59.392326Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nmodel=KNeighborsClassifier(n_neighbors=5, weights= 'uniform')\nmodel.fit(X,y)","metadata":{"execution":{"iopub.status.busy":"2021-10-18T14:31:02.128651Z","iopub.execute_input":"2021-10-18T14:31:02.128952Z","iopub.status.idle":"2021-10-18T14:31:12.436791Z","shell.execute_reply.started":"2021-10-18T14:31:02.128917Z","shell.execute_reply":"2021-10-18T14:31:12.436218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#предсказание модели\npred= model.predict(test_data)","metadata":{"execution":{"iopub.status.busy":"2021-10-18T14:31:15.252196Z","iopub.execute_input":"2021-10-18T14:31:15.252619Z","iopub.status.idle":"2021-10-18T15:05:12.474015Z","shell.execute_reply.started":"2021-10-18T14:31:15.252582Z","shell.execute_reply":"2021-10-18T15:05:12.471767Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output=pd.DataFrame({\n    \"ImageId\": range(1,len(pred)+1),\n    \"Label\": pred})\noutput.head(20)","metadata":{"execution":{"iopub.status.busy":"2021-10-18T15:05:27.531771Z","iopub.execute_input":"2021-10-18T15:05:27.532309Z","iopub.status.idle":"2021-10-18T15:05:27.555695Z","shell.execute_reply.started":"2021-10-18T15:05:27.532245Z","shell.execute_reply":"2021-10-18T15:05:27.554787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2021-10-18T15:05:39.571046Z","iopub.execute_input":"2021-10-18T15:05:39.571854Z","iopub.status.idle":"2021-10-18T15:05:39.635908Z","shell.execute_reply.started":"2021-10-18T15:05:39.571802Z","shell.execute_reply":"2021-10-18T15:05:39.635054Z"},"trusted":true},"execution_count":null,"outputs":[]}]}