{"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":"2022-01-06T03:13:39.579888Z","iopub.execute_input":"2022-01-06T03:13:39.580214Z","iopub.status.idle":"2022-01-06T03:13:39.613343Z","shell.execute_reply.started":"2022-01-06T03:13:39.580128Z","shell.execute_reply":"2022-01-06T03:13:39.612474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trd=pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\nttd=pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:14:45.970393Z","iopub.execute_input":"2022-01-06T03:14:45.971163Z","iopub.status.idle":"2022-01-06T03:14:51.817674Z","shell.execute_reply.started":"2022-01-06T03:14:45.971112Z","shell.execute_reply":"2022-01-06T03:14:51.817029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"s_s=pd.read_csv(\"/kaggle/input/digit-recognizer/sample_submission.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:16:13.562733Z","iopub.execute_input":"2022-01-06T03:16:13.563263Z","iopub.status.idle":"2022-01-06T03:16:13.578126Z","shell.execute_reply.started":"2022-01-06T03:16:13.563222Z","shell.execute_reply":"2022-01-06T03:16:13.577224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trd.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:20:50.351475Z","iopub.execute_input":"2022-01-06T03:20:50.351989Z","iopub.status.idle":"2022-01-06T03:20:50.38173Z","shell.execute_reply.started":"2022-01-06T03:20:50.351934Z","shell.execute_reply":"2022-01-06T03:20:50.38101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ttd.head()","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:21:06.310552Z","iopub.execute_input":"2022-01-06T03:21:06.31118Z","iopub.status.idle":"2022-01-06T03:21:06.331633Z","shell.execute_reply.started":"2022-01-06T03:21:06.311128Z","shell.execute_reply":"2022-01-06T03:21:06.33066Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in ttd.isnull().any():\n    if i==True:\n        sys.exit(\"There is unlabeled data\")\nprint(\"No missing values found\")","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:23:18.840344Z","iopub.execute_input":"2022-01-06T03:23:18.84107Z","iopub.status.idle":"2022-01-06T03:23:18.85645Z","shell.execute_reply.started":"2022-01-06T03:23:18.841032Z","shell.execute_reply":"2022-01-06T03:23:18.855408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y=trd[\"label\"]\nx=trd.drop(\"label\", axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:24:06.053199Z","iopub.execute_input":"2022-01-06T03:24:06.05368Z","iopub.status.idle":"2022-01-06T03:24:06.153664Z","shell.execute_reply.started":"2022-01-06T03:24:06.053639Z","shell.execute_reply":"2022-01-06T03:24:06.152454Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:24:25.57017Z","iopub.execute_input":"2022-01-06T03:24:25.570824Z","iopub.status.idle":"2022-01-06T03:24:25.576727Z","shell.execute_reply.started":"2022-01-06T03:24:25.570783Z","shell.execute_reply":"2022-01-06T03:24:25.575902Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ttd.shape","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:24:38.910432Z","iopub.execute_input":"2022-01-06T03:24:38.910764Z","iopub.status.idle":"2022-01-06T03:24:38.918972Z","shell.execute_reply.started":"2022-01-06T03:24:38.910721Z","shell.execute_reply":"2022-01-06T03:24:38.917991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x=x/255\nttd=ttd/255","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:25:11.680061Z","iopub.execute_input":"2022-01-06T03:25:11.680322Z","iopub.status.idle":"2022-01-06T03:25:11.779886Z","shell.execute_reply.started":"2022-01-06T03:25:11.680294Z","shell.execute_reply":"2022-01-06T03:25:11.778496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nx_tr,x_tt,y_tr,y_tt=train_test_split(x,y,test_size=0.1,random_state=2)","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:26:09.440683Z","iopub.execute_input":"2022-01-06T03:26:09.441643Z","iopub.status.idle":"2022-01-06T03:26:10.701406Z","shell.execute_reply.started":"2022-01-06T03:26:09.441589Z","shell.execute_reply":"2022-01-06T03:26:10.700362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\nmodel = RandomForestClassifier(criterion = \"entropy\")\nmodel.fit(x_tr,y_tr)\nprint(model.score(x_tt,y_tt))","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:26:58.801064Z","iopub.execute_input":"2022-01-06T03:26:58.801355Z","iopub.status.idle":"2022-01-06T03:27:29.987216Z","shell.execute_reply.started":"2022-01-06T03:26:58.801326Z","shell.execute_reply":"2022-01-06T03:27:29.986337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred=model.predict(ttd)\n\nsubmission=pd.DataFrame({\n    \"ImageId\": list(range(1,len(pred)+1)),\n    \"Label\": pred\n})\n\nsubmission.to_csv(\"submision.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-01-06T03:28:17.210319Z","iopub.execute_input":"2022-01-06T03:28:17.210606Z","iopub.status.idle":"2022-01-06T03:28:18.419292Z","shell.execute_reply.started":"2022-01-06T03:28:17.210575Z","shell.execute_reply":"2022-01-06T03:28:18.418277Z"},"trusted":true},"execution_count":null,"outputs":[]}]}