{"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":"# 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":"2023-04-19T02:46:08.482675Z","iopub.execute_input":"2023-04-19T02:46:08.483299Z","iopub.status.idle":"2023-04-19T02:46:08.497770Z","shell.execute_reply.started":"2023-04-19T02:46:08.483263Z","shell.execute_reply":"2023-04-19T02:46:08.496586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_DIR = '/kaggle/input/digit-recognizer'","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:46:16.043742Z","iopub.execute_input":"2023-04-19T02:46:16.044660Z","iopub.status.idle":"2023-04-19T02:46:16.050043Z","shell.execute_reply.started":"2023-04-19T02:46:16.044608Z","shell.execute_reply":"2023-04-19T02:46:16.048302Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_train = pd.read_csv(os.path.join(DATA_DIR, 'train.csv'))\nd_test = pd.read_csv(os.path.join(DATA_DIR, 'test.csv'))","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:46:19.187721Z","iopub.execute_input":"2023-04-19T02:46:19.188534Z","iopub.status.idle":"2023-04-19T02:46:21.857280Z","shell.execute_reply.started":"2023-04-19T02:46:19.188468Z","shell.execute_reply":"2023-04-19T02:46:21.856023Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_submission = pd.read_csv(os.path.join(DATA_DIR, 'sample_submission.csv'))","metadata":{"execution":{"iopub.status.busy":"2023-04-19T03:00:52.769518Z","iopub.execute_input":"2023-04-19T03:00:52.769937Z","iopub.status.idle":"2023-04-19T03:00:52.790365Z","shell.execute_reply.started":"2023-04-19T03:00:52.769905Z","shell.execute_reply":"2023-04-19T03:00:52.789342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_train.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:46:24.357197Z","iopub.execute_input":"2023-04-19T02:46:24.357541Z","iopub.status.idle":"2023-04-19T02:46:24.378574Z","shell.execute_reply.started":"2023-04-19T02:46:24.357509Z","shell.execute_reply":"2023-04-19T02:46:24.377711Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_test.head()","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:46:24.733417Z","iopub.execute_input":"2023-04-19T02:46:24.734469Z","iopub.status.idle":"2023-04-19T02:46:24.752113Z","shell.execute_reply.started":"2023-04-19T02:46:24.734430Z","shell.execute_reply":"2023-04-19T02:46:24.751074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_train.shape","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:46:24.819314Z","iopub.execute_input":"2023-04-19T02:46:24.820305Z","iopub.status.idle":"2023-04-19T02:46:24.825719Z","shell.execute_reply.started":"2023-04-19T02:46:24.820269Z","shell.execute_reply":"2023-04-19T02:46:24.824997Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_test.shape","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:46:26.319421Z","iopub.execute_input":"2023-04-19T02:46:26.319783Z","iopub.status.idle":"2023-04-19T02:46:26.325264Z","shell.execute_reply.started":"2023-04-19T02:46:26.319754Z","shell.execute_reply":"2023-04-19T02:46:26.324365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn import svm\nfrom sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:46:30.099303Z","iopub.execute_input":"2023-04-19T02:46:30.099724Z","iopub.status.idle":"2023-04-19T02:46:30.530364Z","shell.execute_reply.started":"2023-04-19T02:46:30.099682Z","shell.execute_reply":"2023-04-19T02:46:30.529342Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_train_pt, d_valid = train_test_split(d_train, test_size=0.2, stratify=d_train.label)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:47:28.086179Z","iopub.execute_input":"2023-04-19T02:47:28.086565Z","iopub.status.idle":"2023-04-19T02:47:28.280262Z","shell.execute_reply.started":"2023-04-19T02:47:28.086531Z","shell.execute_reply":"2023-04-19T02:47:28.279253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='label', data=d_train_pt)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:47:30.585379Z","iopub.execute_input":"2023-04-19T02:47:30.585757Z","iopub.status.idle":"2023-04-19T02:47:30.786472Z","shell.execute_reply.started":"2023-04-19T02:47:30.585724Z","shell.execute_reply":"2023-04-19T02:47:30.785658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.countplot(x='label', data=d_valid)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:47:31.658278Z","iopub.execute_input":"2023-04-19T02:47:31.659469Z","iopub.status.idle":"2023-04-19T02:47:31.838841Z","shell.execute_reply.started":"2023-04-19T02:47:31.659410Z","shell.execute_reply":"2023-04-19T02:47:31.837965Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_pt_label = d_train_pt.pop('label')\nvalid_label = d_valid.pop('label')","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:47:42.865982Z","iopub.execute_input":"2023-04-19T02:47:42.866341Z","iopub.status.idle":"2023-04-19T02:47:42.877218Z","shell.execute_reply.started":"2023-04-19T02:47:42.866312Z","shell.execute_reply":"2023-04-19T02:47:42.875930Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = svm.SVC()","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:47:43.858263Z","iopub.execute_input":"2023-04-19T02:47:43.858696Z","iopub.status.idle":"2023-04-19T02:47:43.864170Z","shell.execute_reply.started":"2023-04-19T02:47:43.858659Z","shell.execute_reply":"2023-04-19T02:47:43.862932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(d_train_pt, train_pt_label)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:47:53.796324Z","iopub.execute_input":"2023-04-19T02:47:53.796794Z","iopub.status.idle":"2023-04-19T02:49:09.756129Z","shell.execute_reply.started":"2023-04-19T02:47:53.796750Z","shell.execute_reply":"2023-04-19T02:49:09.754980Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"valid_pred = model.predict(d_valid)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:49:16.341134Z","iopub.execute_input":"2023-04-19T02:49:16.341535Z","iopub.status.idle":"2023-04-19T02:50:00.298272Z","shell.execute_reply.started":"2023-04-19T02:49:16.341498Z","shell.execute_reply":"2023-04-19T02:50:00.297139Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"accuracy_score(valid_label, valid_pred)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:50:00.300200Z","iopub.execute_input":"2023-04-19T02:50:00.300562Z","iopub.status.idle":"2023-04-19T02:50:00.308440Z","shell.execute_reply.started":"2023-04-19T02:50:00.300525Z","shell.execute_reply":"2023-04-19T02:50:00.307494Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Submission","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_label = d_train.pop('label')","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:52:33.693289Z","iopub.execute_input":"2023-04-19T02:52:33.693791Z","iopub.status.idle":"2023-04-19T02:52:33.711623Z","shell.execute_reply.started":"2023-04-19T02:52:33.693756Z","shell.execute_reply":"2023-04-19T02:52:33.710790Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = svm.SVC()","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:53:02.243282Z","iopub.execute_input":"2023-04-19T02:53:02.243646Z","iopub.status.idle":"2023-04-19T02:53:02.247680Z","shell.execute_reply.started":"2023-04-19T02:53:02.243598Z","shell.execute_reply":"2023-04-19T02:53:02.246888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.fit(d_train, train_label)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:53:20.047454Z","iopub.execute_input":"2023-04-19T02:53:20.048279Z","iopub.status.idle":"2023-04-19T02:55:20.672070Z","shell.execute_reply.started":"2023-04-19T02:53:20.048239Z","shell.execute_reply":"2023-04-19T02:55:20.670920Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(d_test)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T02:55:20.673768Z","iopub.execute_input":"2023-04-19T02:55:20.674104Z","iopub.status.idle":"2023-04-19T02:57:56.168014Z","shell.execute_reply.started":"2023-04-19T02:55:20.674071Z","shell.execute_reply":"2023-04-19T02:57:56.166492Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_submission['Label'] = y_pred","metadata":{"execution":{"iopub.status.busy":"2023-04-19T03:01:18.358285Z","iopub.execute_input":"2023-04-19T03:01:18.358727Z","iopub.status.idle":"2023-04-19T03:01:18.365130Z","shell.execute_reply.started":"2023-04-19T03:01:18.358688Z","shell.execute_reply":"2023-04-19T03:01:18.363632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d_submission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-04-19T03:01:38.213178Z","iopub.execute_input":"2023-04-19T03:01:38.213547Z","iopub.status.idle":"2023-04-19T03:01:38.248940Z","shell.execute_reply.started":"2023-04-19T03:01:38.213513Z","shell.execute_reply":"2023-04-19T03:01:38.247887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}