{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","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":30646,"isInternetEnabled":true,"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-02-06T13:28:19.721211Z","iopub.execute_input":"2024-02-06T13:28:19.721589Z","iopub.status.idle":"2024-02-06T13:28:20.961707Z","shell.execute_reply.started":"2024-02-06T13:28:19.721559Z","shell.execute_reply":"2024-02-06T13:28:20.960385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom sklearn import svm\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import accuracy_score\n\n# Load the training and test data\ntrain_data = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")\n\n# Separate labels from pixel values in the training data\nX_train = train_data.drop(columns=['label'])\ny_train = train_data['label']\n\n# Normalize pixel values\nX_train = X_train / 255.0\ntest_data = test_data / 255.0\n\n# Split the training data into training and validation sets\nX_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2, random_state=42)\n\n# Define and train the SVM classifier\nclassifier = svm.SVC(kernel='rbf', gamma='scale')\nclassifier.fit(X_train, y_train)\n\n# Make predictions on the validation set\nval_predictions = classifier.predict(X_val)\n\n# Calculate accuracy on the validation set\nval_accuracy = accuracy_score(y_val, val_predictions)\nprint(\"Validation Accuracy:\", val_accuracy)\n\n# Make predictions on the test data\ntest_predictions = classifier.predict(test_data)\n\n# Prepare submission file\nsubmission = pd.DataFrame({'ImageId': range(1, len(test_predictions) + 1), 'Label': test_predictions})\n\n","metadata":{"execution":{"iopub.status.busy":"2024-02-06T16:02:52.976975Z","iopub.execute_input":"2024-02-06T16:02:52.978247Z","iopub.status.idle":"2024-02-06T16:09:16.335480Z","shell.execute_reply.started":"2024-02-06T16:02:52.978186Z","shell.execute_reply":"2024-02-06T16:09:16.334367Z"},"trusted":true},"execution_count":null,"outputs":[]}]}