{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.12.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[],"dockerImageVersionId":28755,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\ntrain = pd.read_csv(\"/kaggle/input/competitions/digit-recognizer/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/competitions/digit-recognizer/test.csv\")\n\nprint(\"Train shape:\", train.shape)\nprint(\"Test shape:\", test.shape)\n\ntrain.head()","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-08-27T16:55:08.420380Z","iopub.execute_input":"2026-08-27T16:55:08.420630Z","iopub.status.idle":"2026-08-27T16:55:11.038976Z","shell.execute_reply.started":"2026-08-27T16:55:08.420612Z","shell.execute_reply":"2026-08-27T16:55:11.038331Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = train.drop(\"label\", axis=1)\ny = train[\"label\"]\n\nX_test = test\n\nprint(\"X shape:\", X.shape)\nprint(\"y shape:\", y.shape)\nprint(\"X_test shape:\", X_test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-27T16:55:40.085406Z","iopub.execute_input":"2026-08-27T16:55:40.085722Z","iopub.status.idle":"2026-08-27T16:55:40.141083Z","shell.execute_reply.started":"2026-08-27T16:55:40.085689Z","shell.execute_reply":"2026-08-27T16:55:40.140457Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.ensemble import RandomForestClassifier\n\nmodel = RandomForestClassifier(\n    n_estimators=100,\n    random_state=42,\n    n_jobs=-1\n)\n\nmodel.fit(X, y)\n\nprint(\"Training completed!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-27T17:01:28.800892Z","iopub.execute_input":"2026-08-27T17:01:28.801304Z","iopub.status.idle":"2026-08-27T17:01:38.395960Z","shell.execute_reply.started":"2026-08-27T17:01:28.801282Z","shell.execute_reply":"2026-08-27T17:01:38.395215Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = model.predict(X_test)\n\nprint(\"Prediction completed!\")\nprint(\"Number of predictions:\", len(predictions))\nprint(\"First 20 predictions:\", predictions[:20])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-27T17:03:09.331032Z","iopub.execute_input":"2026-08-27T17:03:09.331392Z","iopub.status.idle":"2026-08-27T17:03:09.782853Z","shell.execute_reply.started":"2026-08-27T17:03:09.331362Z","shell.execute_reply":"2026-08-27T17:03:09.781015Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n    \"ImageId\": range(1, 28001),\n    \"Label\": predictions\n})\n\nsubmission.to_csv(\n    \"/kaggle/working/submission.csv\",\n    index=False\n)\n\nprint(\"Submission file created!\")\nprint(submission.head())\nprint(\"Total rows:\", len(submission))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-08-27T17:04:35.098326Z","iopub.execute_input":"2026-08-27T17:04:35.098714Z","iopub.status.idle":"2026-08-27T17:04:35.126325Z","shell.execute_reply.started":"2026-08-27T17:04:35.098691Z","shell.execute_reply":"2026-08-27T17:04:35.124490Z"}},"outputs":[],"execution_count":null}]}