{"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-25T14:31:58.694801Z","iopub.execute_input":"2021-12-25T14:31:58.695280Z","iopub.status.idle":"2021-12-25T14:31:59.737604Z","shell.execute_reply.started":"2021-12-25T14:31:58.695191Z","shell.execute_reply":"2021-12-25T14:31:59.736454Z"},"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-25T14:31:59.739664Z","iopub.execute_input":"2021-12-25T14:31:59.740076Z","iopub.status.idle":"2021-12-25T14:32:03.606256Z","shell.execute_reply.started":"2021-12-25T14:31:59.740026Z","shell.execute_reply":"2021-12-25T14:32:03.605243Z"},"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-25T14:32:03.607694Z","iopub.execute_input":"2021-12-25T14:32:03.607918Z","iopub.status.idle":"2021-12-25T14:32:05.688746Z","shell.execute_reply.started":"2021-12-25T14:32:03.607885Z","shell.execute_reply":"2021-12-25T14:32:05.687915Z"},"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-25T14:32:05.691185Z","iopub.execute_input":"2021-12-25T14:32:05.691922Z","iopub.status.idle":"2021-12-25T14:32:05.707548Z","shell.execute_reply.started":"2021-12-25T14:32:05.691870Z","shell.execute_reply":"2021-12-25T14:32:05.706762Z"},"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-25T14:32:05.708528Z","iopub.execute_input":"2021-12-25T14:32:05.708748Z","iopub.status.idle":"2021-12-25T14:32:05.826173Z","shell.execute_reply.started":"2021-12-25T14:32:05.708722Z","shell.execute_reply":"2021-12-25T14:32:05.825422Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-25T14:32:05.827271Z","iopub.execute_input":"2021-12-25T14:32:05.827925Z","iopub.status.idle":"2021-12-25T14:32:05.835469Z","shell.execute_reply.started":"2021-12-25T14:32:05.827883Z","shell.execute_reply":"2021-12-25T14:32:05.834520Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_test.shape","metadata":{"execution":{"iopub.status.busy":"2021-12-25T14:32:05.837601Z","iopub.execute_input":"2021-12-25T14:32:05.838186Z","iopub.status.idle":"2021-12-25T14:32:05.845694Z","shell.execute_reply.started":"2021-12-25T14:32:05.838069Z","shell.execute_reply":"2021-12-25T14:32:05.845105Z"},"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-25T14:32:05.846798Z","iopub.execute_input":"2021-12-25T14:32:05.847419Z","iopub.status.idle":"2021-12-25T14:32:05.958378Z","shell.execute_reply.started":"2021-12-25T14:32:05.847384Z","shell.execute_reply":"2021-12-25T14:32:05.957410Z"},"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-25T14:32:05.959635Z","iopub.execute_input":"2021-12-25T14:32:05.959876Z","iopub.status.idle":"2021-12-25T14:32:06.347651Z","shell.execute_reply.started":"2021-12-25T14:32:05.959846Z","shell.execute_reply":"2021-12-25T14:32:06.346757Z"},"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-25T14:32:06.349673Z","iopub.execute_input":"2021-12-25T14:32:06.349893Z","iopub.status.idle":"2021-12-25T14:32:37.805108Z","shell.execute_reply.started":"2021-12-25T14:32:06.349865Z","shell.execute_reply":"2021-12-25T14:32:37.803964Z"},"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-25T14:32:37.806331Z","iopub.execute_input":"2021-12-25T14:32:37.806602Z","iopub.status.idle":"2021-12-25T14:32:38.991731Z","shell.execute_reply.started":"2021-12-25T14:32:37.806567Z","shell.execute_reply":"2021-12-25T14:32:38.990823Z"},"trusted":true},"execution_count":null,"outputs":[]}]}