{"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 sys\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport seaborn as sns\n%matplotlib inline","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-12-26T16:40:56.134561Z","iopub.execute_input":"2021-12-26T16:40:56.134909Z","iopub.status.idle":"2021-12-26T16:40:56.142232Z","shell.execute_reply.started":"2021-12-26T16:40:56.134871Z","shell.execute_reply":"2021-12-26T16:40:56.141359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_train = pd.read_csv(\"../input/digit-recognizer/train.csv\")\n\ndf_train.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:40:56.143584Z","iopub.execute_input":"2021-12-26T16:40:56.144365Z","iopub.status.idle":"2021-12-26T16:40:58.840057Z","shell.execute_reply.started":"2021-12-26T16:40:56.144311Z","shell.execute_reply":"2021-12-26T16:40:58.839139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test = pd.read_csv(\"../input/digit-recognizer/test.csv\")\n\ndf_test.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:40:58.842119Z","iopub.execute_input":"2021-12-26T16:40:58.842369Z","iopub.status.idle":"2021-12-26T16:41:00.521628Z","shell.execute_reply.started":"2021-12-26T16:40:58.842341Z","shell.execute_reply":"2021-12-26T16:41:00.520740Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in df_test.isnull().any():\n    if i == True:\n        sys.exit(\"There is unlabeled data\")\nprint(\"No missing values found\")","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:00.523196Z","iopub.execute_input":"2021-12-26T16:41:00.523678Z","iopub.status.idle":"2021-12-26T16:41:00.542605Z","shell.execute_reply.started":"2021-12-26T16:41:00.523642Z","shell.execute_reply":"2021-12-26T16:41:00.541998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in df_train.isnull().any():\n    if i == True:\n        sys.exit(\"There is unlabeled data\")\nprint(\"No missing values found\")","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:00.544196Z","iopub.execute_input":"2021-12-26T16:41:00.544841Z","iopub.status.idle":"2021-12-26T16:41:00.566601Z","shell.execute_reply.started":"2021-12-26T16:41:00.544802Z","shell.execute_reply":"2021-12-26T16:41:00.565943Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y = df_train[\"label\"]\nx = df_train.drop(\"label\", axis=1)","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:00.567768Z","iopub.execute_input":"2021-12-26T16:41:00.568058Z","iopub.status.idle":"2021-12-26T16:41:00.661860Z","shell.execute_reply.started":"2021-12-26T16:41:00.568026Z","shell.execute_reply":"2021-12-26T16:41:00.660956Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:00.663097Z","iopub.execute_input":"2021-12-26T16:41:00.663310Z","iopub.status.idle":"2021-12-26T16:41:00.669161Z","shell.execute_reply.started":"2021-12-26T16:41:00.663285Z","shell.execute_reply":"2021-12-26T16:41:00.668300Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:00.670500Z","iopub.execute_input":"2021-12-26T16:41:00.670990Z","iopub.status.idle":"2021-12-26T16:41:00.682642Z","shell.execute_reply.started":"2021-12-26T16:41:00.670947Z","shell.execute_reply":"2021-12-26T16:41:00.681707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = x / 255.0\ndf_test = df_test / 255.0","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:00.684185Z","iopub.execute_input":"2021-12-26T16:41:00.684494Z","iopub.status.idle":"2021-12-26T16:41:00.807988Z","shell.execute_reply.started":"2021-12-26T16:41:00.684452Z","shell.execute_reply":"2021-12-26T16:41:00.806911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nx_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.1, random_state=2)","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:00.809396Z","iopub.execute_input":"2021-12-26T16:41:00.809721Z","iopub.status.idle":"2021-12-26T16:41:01.030645Z","shell.execute_reply.started":"2021-12-26T16:41:00.809680Z","shell.execute_reply":"2021-12-26T16:41:01.030000Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\nmodel = RandomForestClassifier(criterion = \"entropy\")\nmodel.fit(x_train, y_train)\n\nprint(model.score(x_test, y_test))","metadata":{"execution":{"iopub.status.busy":"2021-12-26T16:41:01.033412Z","iopub.execute_input":"2021-12-26T16:41:01.034019Z","iopub.status.idle":"2021-12-26T16:41:32.065675Z","shell.execute_reply.started":"2021-12-26T16:41:01.033966Z","shell.execute_reply":"2021-12-26T16:41:32.064682Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = model.predict(df_test)\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":"2021-12-26T16:41:32.067106Z","iopub.execute_input":"2021-12-26T16:41:32.067420Z","iopub.status.idle":"2021-12-26T16:41:33.256240Z","shell.execute_reply.started":"2021-12-26T16:41:32.067376Z","shell.execute_reply":"2021-12-26T16:41:33.255549Z"},"trusted":true},"execution_count":null,"outputs":[]}]}