{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30839,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:07:08.936050Z","iopub.execute_input":"2025-01-23T21:07:08.936406Z","iopub.status.idle":"2025-01-23T21:07:08.940298Z","shell.execute_reply.started":"2025-01-23T21:07:08.936375Z","shell.execute_reply":"2025-01-23T21:07:08.939313Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:07:29.558613Z","iopub.execute_input":"2025-01-23T21:07:29.558992Z","iopub.status.idle":"2025-01-23T21:07:32.734839Z","shell.execute_reply.started":"2025-01-23T21:07:29.558960Z","shell.execute_reply":"2025-01-23T21:07:32.733625Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:07:37.782803Z","iopub.execute_input":"2025-01-23T21:07:37.783273Z","iopub.status.idle":"2025-01-23T21:07:37.790475Z","shell.execute_reply.started":"2025-01-23T21:07:37.783231Z","shell.execute_reply":"2025-01-23T21:07:37.789376Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.columns","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:07:46.078676Z","iopub.execute_input":"2025-01-23T21:07:46.079066Z","iopub.status.idle":"2025-01-23T21:07:46.086286Z","shell.execute_reply.started":"2025-01-23T21:07:46.079033Z","shell.execute_reply":"2025-01-23T21:07:46.085294Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = df.drop(columns=['label'])\ny = df['label']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:08:12.782756Z","iopub.execute_input":"2025-01-23T21:08:12.783124Z","iopub.status.idle":"2025-01-23T21:08:12.914303Z","shell.execute_reply.started":"2025-01-23T21:08:12.783094Z","shell.execute_reply":"2025-01-23T21:08:12.913186Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier\nfrom sklearn.metrics import accuracy_score, classification_report","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:12:38.559017Z","iopub.execute_input":"2025-01-23T21:12:38.559345Z","iopub.status.idle":"2025-01-23T21:12:38.563473Z","shell.execute_reply.started":"2025-01-23T21:12:38.559322Z","shell.execute_reply":"2025-01-23T21:12:38.562443Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\nprint(len(X_train))\nprint(len(X_test))\nprint(len(y_train))\nprint(len(y_test))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:10:00.871147Z","iopub.execute_input":"2025-01-23T21:10:00.871656Z","iopub.status.idle":"2025-01-23T21:10:01.122030Z","shell.execute_reply.started":"2025-01-23T21:10:00.871624Z","shell.execute_reply":"2025-01-23T21:10:01.120992Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"rf_model = RandomForestClassifier()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:10:44.034664Z","iopub.execute_input":"2025-01-23T21:10:44.035062Z","iopub.status.idle":"2025-01-23T21:10:44.039226Z","shell.execute_reply.started":"2025-01-23T21:10:44.035033Z","shell.execute_reply":"2025-01-23T21:10:44.038106Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"rf_model.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:10:54.377650Z","iopub.execute_input":"2025-01-23T21:10:54.378028Z","iopub.status.idle":"2025-01-23T21:11:17.853998Z","shell.execute_reply.started":"2025-01-23T21:10:54.377997Z","shell.execute_reply":"2025-01-23T21:11:17.853004Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred_rf = rf_model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:11:36.014800Z","iopub.execute_input":"2025-01-23T21:11:36.015188Z","iopub.status.idle":"2025-01-23T21:11:36.344049Z","shell.execute_reply.started":"2025-01-23T21:11:36.015158Z","shell.execute_reply":"2025-01-23T21:11:36.343058Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"accuracy_score(y_test, y_pred_rf)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:11:52.182939Z","iopub.execute_input":"2025-01-23T21:11:52.183286Z","iopub.status.idle":"2025-01-23T21:11:52.190916Z","shell.execute_reply.started":"2025-01-23T21:11:52.183258Z","shell.execute_reply":"2025-01-23T21:11:52.189974Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"classification_report(y_test, y_pred_rf)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:12:05.550618Z","iopub.execute_input":"2025-01-23T21:12:05.551014Z","iopub.status.idle":"2025-01-23T21:12:05.584444Z","shell.execute_reply.started":"2025-01-23T21:12:05.550980Z","shell.execute_reply":"2025-01-23T21:12:05.583524Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ada = AdaBoostClassifier()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:12:50.651050Z","iopub.execute_input":"2025-01-23T21:12:50.651367Z","iopub.status.idle":"2025-01-23T21:12:50.655666Z","shell.execute_reply.started":"2025-01-23T21:12:50.651342Z","shell.execute_reply":"2025-01-23T21:12:50.654611Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ada.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:12:59.375586Z","iopub.execute_input":"2025-01-23T21:12:59.375945Z","iopub.status.idle":"2025-01-23T21:13:27.449185Z","shell.execute_reply.started":"2025-01-23T21:12:59.375880Z","shell.execute_reply":"2025-01-23T21:13:27.448186Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred_ada = ada.predict(X_test)\naccuracy_score(y_test, y_pred_ada)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:13:30.003724Z","iopub.execute_input":"2025-01-23T21:13:30.004107Z","iopub.status.idle":"2025-01-23T21:13:30.656140Z","shell.execute_reply.started":"2025-01-23T21:13:30.004074Z","shell.execute_reply":"2025-01-23T21:13:30.655172Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:13:53.800039Z","iopub.execute_input":"2025-01-23T21:13:53.800390Z","iopub.status.idle":"2025-01-23T21:13:55.661603Z","shell.execute_reply.started":"2025-01-23T21:13:53.800359Z","shell.execute_reply":"2025-01-23T21:13:55.660793Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:14:02.260370Z","iopub.execute_input":"2025-01-23T21:14:02.260725Z","iopub.status.idle":"2025-01-23T21:14:02.281581Z","shell.execute_reply.started":"2025-01-23T21:14:02.260697Z","shell.execute_reply":"2025-01-23T21:14:02.280759Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ImageID = range(1, len(test) + 1)\nImageID","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:19:34.041786Z","iopub.execute_input":"2025-01-23T21:19:34.042216Z","iopub.status.idle":"2025-01-23T21:19:34.047984Z","shell.execute_reply.started":"2025-01-23T21:19:34.042183Z","shell.execute_reply":"2025-01-23T21:19:34.046999Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_pred_rf = rf_model.predict(test)\nlen(test_pred_rf)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:18:45.164086Z","iopub.execute_input":"2025-01-23T21:18:45.164403Z","iopub.status.idle":"2025-01-23T21:18:46.263959Z","shell.execute_reply.started":"2025-01-23T21:18:45.164379Z","shell.execute_reply":"2025-01-23T21:18:46.262715Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(len(ImageID))\nprint(len(test_pred_rf))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:19:37.031792Z","iopub.execute_input":"2025-01-23T21:19:37.032171Z","iopub.status.idle":"2025-01-23T21:19:37.036961Z","shell.execute_reply.started":"2025-01-23T21:19:37.032141Z","shell.execute_reply":"2025-01-23T21:19:37.035724Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"result_rf = pd.DataFrame({'ImageId': ImageID, 'Label':test_pred_rf})\nresult_rf","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:19:39.494735Z","iopub.execute_input":"2025-01-23T21:19:39.495095Z","iopub.status.idle":"2025-01-23T21:19:39.505874Z","shell.execute_reply.started":"2025-01-23T21:19:39.495065Z","shell.execute_reply":"2025-01-23T21:19:39.504829Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"result_rf.to_csv('submission.csv', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-01-23T21:20:03.742858Z","iopub.execute_input":"2025-01-23T21:20:03.743325Z","iopub.status.idle":"2025-01-23T21:20:03.785764Z","shell.execute_reply.started":"2025-01-23T21:20:03.743286Z","shell.execute_reply":"2025-01-23T21:20:03.784696Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}