{"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":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session\n\n# Use the kagglehub client library to attach Kaggle resources like competitions, datasets, and models to your session\n# Learn more about kagglehub: https://github.com/Kaggle/kagglehub/blob/main/README.md\n\nimport kagglehub\n# kagglehub.dataset_download('<owner>/<dataset-slug>')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:36:28.782610Z","iopub.execute_input":"2026-09-14T19:36:28.782884Z","iopub.status.idle":"2026-09-14T19:36:30.839489Z","shell.execute_reply.started":"2026-09-14T19:36:28.782858Z","shell.execute_reply":"2026-09-14T19:36:30.838962Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Digit Recognizer - Machine Learning Project\n# ============================================\n\n# Data manipulation\nimport pandas as pd\nimport numpy as np\n\n# Data visualization\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\n# Machine Learning\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.ensemble import RandomForestClassifier","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:41:33.758468Z","iopub.execute_input":"2026-09-14T19:41:33.758691Z","iopub.status.idle":"2026-09-14T19:41:35.133406Z","shell.execute_reply.started":"2026-09-14T19:41:33.758672Z","shell.execute_reply":"2026-09-14T19:41:35.132575Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Load Dataset\n# ============================================\n\ntrain = pd.read_csv(\n    '/kaggle/input/competitions/digit-recognizer/train.csv'\n)\n\ntest = pd.read_csv(\n    '/kaggle/input/competitions/digit-recognizer/test.csv'\n)\n\nprint(\"Train shape:\", train.shape)\nprint(\"Test shape:\", test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:42:00.702621Z","iopub.execute_input":"2026-09-14T19:42:00.703092Z","iopub.status.idle":"2026-09-14T19:42:03.675889Z","shell.execute_reply.started":"2026-09-14T19:42:00.703067Z","shell.execute_reply":"2026-09-14T19:42:03.675348Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Display the first 5 rows\n\ntrain.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:42:34.232930Z","iopub.execute_input":"2026-09-14T19:42:34.233205Z","iopub.status.idle":"2026-09-14T19:42:34.267501Z","shell.execute_reply.started":"2026-09-14T19:42:34.233182Z","shell.execute_reply":"2026-09-14T19:42:34.266678Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Display column names\n\nprint(train.columns)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:42:55.796089Z","iopub.execute_input":"2026-09-14T19:42:55.796334Z","iopub.status.idle":"2026-09-14T19:42:55.800242Z","shell.execute_reply.started":"2026-09-14T19:42:55.796315Z","shell.execute_reply":"2026-09-14T19:42:55.799455Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Basic information about the dataset\n\nprint(\"Missing values:\", train.isnull().sum().sum())\nprint(\"Duplicate rows:\", train.duplicated().sum())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:43:24.674267Z","iopub.execute_input":"2026-09-14T19:43:24.674515Z","iopub.status.idle":"2026-09-14T19:43:24.994967Z","shell.execute_reply.started":"2026-09-14T19:43:24.674488Z","shell.execute_reply":"2026-09-14T19:43:24.994221Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Distribution of handwritten digits\n\nprint(train['label'].value_counts().sort_index())\n\nplt.figure(figsize=(8, 5))\nsns.countplot(x=train['label'])\nplt.title('Distribution of Digits')\nplt.xlabel('Digit')\nplt.ylabel('Count')\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:43:44.057342Z","iopub.execute_input":"2026-09-14T19:43:44.058121Z","iopub.status.idle":"2026-09-14T19:43:44.346711Z","shell.execute_reply.started":"2026-09-14T19:43:44.058097Z","shell.execute_reply":"2026-09-14T19:43:44.345998Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Display one handwritten digit\n\nimage = train.drop('label', axis=1).iloc[0].values\nlabel = train['label'].iloc[0]\n\nplt.figure(figsize=(4, 4))\nplt.imshow(image.reshape(28, 28), cmap='gray')\nplt.title(f'Label: {label}')\nplt.axis('off')\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:43:57.990825Z","iopub.execute_input":"2026-09-14T19:43:57.991097Z","iopub.status.idle":"2026-09-14T19:43:58.086924Z","shell.execute_reply.started":"2026-09-14T19:43:57.991077Z","shell.execute_reply":"2026-09-14T19:43:58.086186Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Prepare Data\n# ============================================\n\n# Separate features (X) and target (y)\nX = train.drop('label', axis=1)\ny = train['label']\n\n# Test data\nX_test = test\n\nprint(\"X shape:\", X.shape)\nprint(\"y shape:\", y.shape)\nprint(\"Test shape:\", X_test.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:45:39.126129Z","iopub.execute_input":"2026-09-14T19:45:39.126425Z","iopub.status.idle":"2026-09-14T19:45:39.175329Z","shell.execute_reply.started":"2026-09-14T19:45:39.126404Z","shell.execute_reply":"2026-09-14T19:45:39.174551Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Split Data into Training and Validation\n# ============================================\n\nX_train, X_val, y_train, y_val = train_test_split(\n    X,\n    y,\n    test_size=0.2,\n    random_state=42,\n    stratify=y\n)\n\nprint(\"Training data:\", X_train.shape)\nprint(\"Validation data:\", X_val.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:46:39.844103Z","iopub.execute_input":"2026-09-14T19:46:39.844372Z","iopub.status.idle":"2026-09-14T19:46:40.034732Z","shell.execute_reply.started":"2026-09-14T19:46:39.844350Z","shell.execute_reply":"2026-09-14T19:46:40.033737Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Train Random Forest Model\n# ============================================\n\nmodel = RandomForestClassifier(\n    n_estimators=100,\n    random_state=42,\n    n_jobs=-1\n)\n\nmodel.fit(X_train, y_train)\n\nprint(\"Model training completed successfully!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:47:32.632206Z","iopub.execute_input":"2026-09-14T19:47:32.632480Z","iopub.status.idle":"2026-09-14T19:47:39.884837Z","shell.execute_reply.started":"2026-09-14T19:47:32.632456Z","shell.execute_reply":"2026-09-14T19:47:39.883770Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Evaluate Model\n# ============================================\n\n# Make predictions on validation data\ny_pred = model.predict(X_val)\n\n# Calculate accuracy\naccuracy = accuracy_score(y_val, y_pred)\n\nprint(f\"Validation Accuracy: {accuracy:.4f}\")\nprint(f\"Validation Accuracy: {accuracy * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:48:17.672171Z","iopub.execute_input":"2026-09-14T19:48:17.672416Z","iopub.status.idle":"2026-09-14T19:48:17.775950Z","shell.execute_reply.started":"2026-09-14T19:48:17.672399Z","shell.execute_reply":"2026-09-14T19:48:17.775372Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Predict Test Data\n# ============================================\n\ntest_predictions = model.predict(X_test)\n\nprint(\"Number of predictions:\", len(test_predictions))\nprint(\"First 20 predictions:\", test_predictions[:20])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:49:12.835103Z","iopub.execute_input":"2026-09-14T19:49:12.835356Z","iopub.status.idle":"2026-09-14T19:49:13.129634Z","shell.execute_reply.started":"2026-09-14T19:49:12.835337Z","shell.execute_reply":"2026-09-14T19:49:13.128610Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Create Submission File\n# ============================================\n\nsubmission = pd.DataFrame({\n    'ImageId': range(1, len(test_predictions) + 1),\n    'Label': test_predictions\n})\n\nsubmission.to_csv('submission.csv', index=False)\n\nprint(\"Submission file created successfully!\")\nprint(submission.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T19:49:45.304144Z","iopub.execute_input":"2026-09-14T19:49:45.304399Z","iopub.status.idle":"2026-09-14T19:49:45.328286Z","shell.execute_reply.started":"2026-09-14T19:49:45.304380Z","shell.execute_reply":"2026-09-14T19:49:45.327749Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 2 - Improved Random Forest\n# ============================================\n\nmodel_2 = RandomForestClassifier(\n    n_estimators=200,\n    max_features='sqrt',\n    random_state=42,\n    n_jobs=-1\n)\n\nmodel_2.fit(X_train, y_train)\n\nprint(\"Improved Random Forest training completed!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:00:08.523192Z","iopub.execute_input":"2026-09-14T20:00:08.523453Z","iopub.status.idle":"2026-09-14T20:00:22.953707Z","shell.execute_reply.started":"2026-09-14T20:00:08.523433Z","shell.execute_reply":"2026-09-14T20:00:22.952771Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Evaluate Model 2\n# ============================================\n\ny_pred_2 = model_2.predict(X_val)\n\naccuracy_2 = accuracy_score(y_val, y_pred_2)\n\nprint(f\"Model 2 Validation Accuracy: {accuracy_2:.4f}\")\nprint(f\"Model 2 Validation Accuracy: {accuracy_2 * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:01:02.830902Z","iopub.execute_input":"2026-09-14T20:01:02.831159Z","iopub.status.idle":"2026-09-14T20:01:03.023248Z","shell.execute_reply.started":"2026-09-14T20:01:02.831140Z","shell.execute_reply":"2026-09-14T20:01:03.022279Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 2 - Test Predictions\n# ============================================\n\ntest_predictions_2 = model_2.predict(X_test)\n\nprint(\"Number of predictions:\", len(test_predictions_2))\nprint(\"First 20 predictions:\", test_predictions_2[:20])\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:01:36.314601Z","iopub.execute_input":"2026-09-14T20:01:36.314904Z","iopub.status.idle":"2026-09-14T20:01:36.878733Z","shell.execute_reply.started":"2026-09-14T20:01:36.314882Z","shell.execute_reply":"2026-09-14T20:01:36.877977Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Create Submission 2\n# ============================================\n\nsubmission_2 = pd.DataFrame({\n    'ImageId': range(1, len(test_predictions_2) + 1),\n    'Label': test_predictions_2\n})\n\nsubmission_2.to_csv('submission_2.csv', index=False)\n\nprint(\"Submission 2 file created successfully!\")\nprint(submission_2.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:02:03.715646Z","iopub.execute_input":"2026-09-14T20:02:03.715948Z","iopub.status.idle":"2026-09-14T20:02:03.736697Z","shell.execute_reply.started":"2026-09-14T20:02:03.715926Z","shell.execute_reply":"2026-09-14T20:02:03.735768Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 3 - KNN Model\n# ============================================\n\nfrom sklearn.neighbors import KNeighborsClassifier\n\nprint(\"KNN library imported successfully!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:05:56.343966Z","iopub.execute_input":"2026-09-14T20:05:56.344258Z","iopub.status.idle":"2026-09-14T20:05:56.348179Z","shell.execute_reply.started":"2026-09-14T20:05:56.344238Z","shell.execute_reply":"2026-09-14T20:05:56.347571Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Train KNN Model\n# ============================================\n\nknn_model = KNeighborsClassifier(\n    n_neighbors=3,\n    n_jobs=-1\n)\n\nknn_model.fit(X_train, y_train)\n\nprint(\"KNN model training completed!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:06:27.626976Z","iopub.execute_input":"2026-09-14T20:06:27.627224Z","iopub.status.idle":"2026-09-14T20:06:27.709127Z","shell.execute_reply.started":"2026-09-14T20:06:27.627207Z","shell.execute_reply":"2026-09-14T20:06:27.708258Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Evaluate KNN Model\n# ============================================\n\ny_pred_knn = knn_model.predict(X_val)\n\naccuracy_knn = accuracy_score(y_val, y_pred_knn)\n\nprint(f\"KNN Validation Accuracy: {accuracy_knn:.4f}\")\nprint(f\"KNN Validation Accuracy: {accuracy_knn * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:07:13.024148Z","iopub.execute_input":"2026-09-14T20:07:13.024402Z","iopub.status.idle":"2026-09-14T20:07:20.723694Z","shell.execute_reply.started":"2026-09-14T20:07:13.024384Z","shell.execute_reply":"2026-09-14T20:07:20.722850Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 3 - KNN Test Predictions\n# ============================================\n\ntest_predictions_knn = knn_model.predict(X_test)\n\nprint(\"Number of predictions:\", len(test_predictions_knn))\nprint(\"First 20 predictions:\", test_predictions_knn[:20])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:08:12.875687Z","iopub.execute_input":"2026-09-14T20:08:12.876613Z","iopub.status.idle":"2026-09-14T20:08:37.962706Z","shell.execute_reply.started":"2026-09-14T20:08:12.876566Z","shell.execute_reply":"2026-09-14T20:08:37.962281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Create Submission 3\n# ============================================\n\nsubmission_3 = pd.DataFrame({\n    'ImageId': range(1, len(test_predictions_knn) + 1),\n    'Label': test_predictions_knn\n})\n\nsubmission_3.to_csv('submission_3.csv', index=False)\n\nprint(\"Submission 3 file created successfully!\")\nprint(submission_3.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:09:25.305151Z","iopub.execute_input":"2026-09-14T20:09:25.305394Z","iopub.status.idle":"2026-09-14T20:09:25.325869Z","shell.execute_reply.started":"2026-09-14T20:09:25.305375Z","shell.execute_reply":"2026-09-14T20:09:25.325188Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 4 - SVM Model\n# ============================================\n\nfrom sklearn.svm import SVC\n\nprint(\"SVM library imported successfully!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:12:43.387072Z","iopub.execute_input":"2026-09-14T20:12:43.387331Z","iopub.status.idle":"2026-09-14T20:12:43.391496Z","shell.execute_reply.started":"2026-09-14T20:12:43.387308Z","shell.execute_reply":"2026-09-14T20:12:43.390716Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Train SVM Model\n# ============================================\n\nsvm_model = SVC(\n    kernel='rbf',\n    C=10,\n    gamma='scale'\n)\n\nsvm_model.fit(X_train, y_train)\n\nprint(\"SVM model training completed!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:13:19.790512Z","iopub.execute_input":"2026-09-14T20:13:19.790766Z","iopub.status.idle":"2026-09-14T20:14:24.845615Z","shell.execute_reply.started":"2026-09-14T20:13:19.790747Z","shell.execute_reply":"2026-09-14T20:14:24.845119Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Evaluate SVM Model\n# ============================================\n\ny_pred_svm = svm_model.predict(X_val)\n\naccuracy_svm = accuracy_score(y_val, y_pred_svm)\n\nprint(f\"SVM Validation Accuracy: {accuracy_svm:.4f}\")\nprint(f\"SVM Validation Accuracy: {accuracy_svm * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:14:51.500129Z","iopub.execute_input":"2026-09-14T20:14:51.500373Z","iopub.status.idle":"2026-09-14T20:15:29.898451Z","shell.execute_reply.started":"2026-09-14T20:14:51.500352Z","shell.execute_reply":"2026-09-14T20:15:29.897310Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 4 - SVM Test Predictions\n# ============================================\n\ntest_predictions_svm = svm_model.predict(X_test)\n\nprint(\"Number of predictions:\", len(test_predictions_svm))\nprint(\"First 20 predictions:\", test_predictions_svm[:20])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:16:26.956034Z","iopub.execute_input":"2026-09-14T20:16:26.956297Z","iopub.status.idle":"2026-09-14T20:18:37.058600Z","shell.execute_reply.started":"2026-09-14T20:16:26.956275Z","shell.execute_reply":"2026-09-14T20:18:37.057672Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Create Submission 4\n# ============================================\n\nsubmission_4 = pd.DataFrame({\n    'ImageId': range(1, len(test_predictions_svm) + 1),\n    'Label': test_predictions_svm\n})\n\nsubmission_4.to_csv('submission_4.csv', index=False)\n\nprint(\"Submission 4 file created successfully!\")\nprint(submission_4.head())\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:20:17.455994Z","iopub.execute_input":"2026-09-14T20:20:17.456271Z","iopub.status.idle":"2026-09-14T20:20:17.477235Z","shell.execute_reply.started":"2026-09-14T20:20:17.456246Z","shell.execute_reply":"2026-09-14T20:20:17.476584Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 5 - Normalized SVM\n# ============================================\n\n# Normalize pixel values from 0-255 to 0-1\nX_train_scaled = X_train / 255.0\nX_val_scaled = X_val / 255.0\nX_test_scaled = X_test / 255.0\n\nprint(\"Data normalization completed!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:27:20.156173Z","iopub.execute_input":"2026-09-14T20:27:20.156961Z","iopub.status.idle":"2026-09-14T20:27:20.222205Z","shell.execute_reply.started":"2026-09-14T20:27:20.156938Z","shell.execute_reply":"2026-09-14T20:27:20.221569Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 5 - Train Normalized SVM\n# ============================================\n\nsvm_scaled = SVC(\n    kernel='rbf',\n    C=10,\n    gamma='scale'\n)\n\nsvm_scaled.fit(X_train_scaled, y_train)\n\nprint(\"Normalized SVM training completed!\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:27:45.176668Z","iopub.execute_input":"2026-09-14T20:27:45.176948Z","iopub.status.idle":"2026-09-14T20:28:50.404677Z","shell.execute_reply.started":"2026-09-14T20:27:45.176927Z","shell.execute_reply":"2026-09-14T20:28:50.403924Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Evaluate Normalized SVM\n# ============================================\n\ny_pred_scaled = svm_scaled.predict(X_val_scaled)\n\naccuracy_scaled = accuracy_score(y_val, y_pred_scaled)\n\nprint(f\"Normalized SVM Validation Accuracy: {accuracy_scaled:.4f}\")\nprint(f\"Normalized SVM Validation Accuracy: {accuracy_scaled * 100:.2f}%\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:29:21.294018Z","iopub.execute_input":"2026-09-14T20:29:21.294273Z","iopub.status.idle":"2026-09-14T20:29:59.686595Z","shell.execute_reply.started":"2026-09-14T20:29:21.294252Z","shell.execute_reply":"2026-09-14T20:29:59.685536Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Final Model - Train SVM on All Data\n# ============================================\n\nX_scaled = X / 255.0\nX_test_scaled = X_test / 255.0\n\nfinal_svm = SVC(\n    kernel='rbf',\n    C=10,\n    gamma='scale'\n)\n\nfinal_svm.fit(X_scaled, y)\n\nprint(\"Final SVM training completed!\")\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:30:38.184654Z","iopub.execute_input":"2026-09-14T20:30:38.185039Z","iopub.status.idle":"2026-09-14T20:32:08.721400Z","shell.execute_reply.started":"2026-09-14T20:30:38.185018Z","shell.execute_reply":"2026-09-14T20:32:08.720368Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Submission 5 - Final Test Predictions\n# ============================================\n\nfinal_predictions = final_svm.predict(X_test_scaled)\n\nprint(\"Number of predictions:\", len(final_predictions))\nprint(\"First 20 predictions:\", final_predictions[:20])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:33:02.268121Z","iopub.execute_input":"2026-09-14T20:33:02.268380Z","iopub.status.idle":"2026-09-14T20:35:17.914192Z","shell.execute_reply.started":"2026-09-14T20:33:02.268361Z","shell.execute_reply":"2026-09-14T20:35:17.913522Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# ============================================\n# Create Final Submission 5\n# ============================================\n\nsubmission_5 = pd.DataFrame({\n    'ImageId': range(1, len(final_predictions) + 1),\n    'Label': final_predictions\n})\n\nsubmission_5.to_csv('submission_5.csv', index=False)\n\nprint(\"Final Submission 5 created successfully!\")\nprint(submission_5.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2026-09-14T20:35:58.343754Z","iopub.execute_input":"2026-09-14T20:35:58.344114Z","iopub.status.idle":"2026-09-14T20:35:58.362762Z","shell.execute_reply.started":"2026-09-14T20:35:58.344092Z","shell.execute_reply":"2026-09-14T20:35:58.361977Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}