{"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-27T15:42:46.316529Z","iopub.execute_input":"2021-12-27T15:42:46.317292Z","iopub.status.idle":"2021-12-27T15:42:47.392054Z","shell.execute_reply.started":"2021-12-27T15:42:46.317177Z","shell.execute_reply":"2021-12-27T15:42:47.391219Z"},"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-27T15:42:47.394006Z","iopub.execute_input":"2021-12-27T15:42:47.394326Z","iopub.status.idle":"2021-12-27T15:42:51.260208Z","shell.execute_reply.started":"2021-12-27T15:42:47.394285Z","shell.execute_reply":"2021-12-27T15:42:51.259329Z"},"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-27T15:42:51.261388Z","iopub.execute_input":"2021-12-27T15:42:51.261629Z","iopub.status.idle":"2021-12-27T15:42:53.366168Z","shell.execute_reply.started":"2021-12-27T15:42:51.261585Z","shell.execute_reply":"2021-12-27T15:42:53.365198Z"},"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-27T15:42:53.369736Z","iopub.execute_input":"2021-12-27T15:42:53.369989Z","iopub.status.idle":"2021-12-27T15:42:53.384997Z","shell.execute_reply.started":"2021-12-27T15:42:53.369959Z","shell.execute_reply":"2021-12-27T15:42:53.384331Z"},"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-27T15:42:53.386211Z","iopub.execute_input":"2021-12-27T15:42:53.387227Z","iopub.status.idle":"2021-12-27T15:42:53.405652Z","shell.execute_reply.started":"2021-12-27T15:42:53.387173Z","shell.execute_reply":"2021-12-27T15:42:53.404676Z"},"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-27T15:42:53.408312Z","iopub.execute_input":"2021-12-27T15:42:53.408812Z","iopub.status.idle":"2021-12-27T15:42:53.53202Z","shell.execute_reply.started":"2021-12-27T15:42:53.40877Z","shell.execute_reply":"2021-12-27T15:42:53.531156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-27T15:42:53.533171Z","iopub.execute_input":"2021-12-27T15:42:53.533391Z","iopub.status.idle":"2021-12-27T15:42:53.539802Z","shell.execute_reply.started":"2021-12-27T15:42:53.533365Z","shell.execute_reply":"2021-12-27T15:42:53.538749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-27T15:42:53.542606Z","iopub.execute_input":"2021-12-27T15:42:53.542945Z","iopub.status.idle":"2021-12-27T15:42:53.55395Z","shell.execute_reply.started":"2021-12-27T15:42:53.542911Z","shell.execute_reply":"2021-12-27T15:42:53.553053Z"},"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-27T15:42:53.555546Z","iopub.execute_input":"2021-12-27T15:42:53.555839Z","iopub.status.idle":"2021-12-27T15:42:53.675139Z","shell.execute_reply.started":"2021-12-27T15:42:53.555808Z","shell.execute_reply":"2021-12-27T15:42:53.674525Z"},"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-27T15:42:53.676047Z","iopub.execute_input":"2021-12-27T15:42:53.676284Z","iopub.status.idle":"2021-12-27T15:42:54.084349Z","shell.execute_reply.started":"2021-12-27T15:42:53.676244Z","shell.execute_reply":"2021-12-27T15:42:54.083512Z"},"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-27T15:42:54.086658Z","iopub.execute_input":"2021-12-27T15:42:54.086914Z","iopub.status.idle":"2021-12-27T15:43:25.469171Z","shell.execute_reply.started":"2021-12-27T15:42:54.086883Z","shell.execute_reply":"2021-12-27T15:43:25.46813Z"},"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-27T15:43:25.470229Z","iopub.execute_input":"2021-12-27T15:43:25.470449Z","iopub.status.idle":"2021-12-27T15:43:26.654522Z","shell.execute_reply.started":"2021-12-27T15:43:25.470423Z","shell.execute_reply":"2021-12-27T15:43:26.653699Z"},"trusted":true},"execution_count":null,"outputs":[]}]}