{"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":"import numpy as np\nimport pandas as pd\nfrom sklearn import svm\nimport matplotlib.pyplot as pt\nimport seaborn as sns\nfrom sklearn.preprocessing import scale\nfrom sklearn.model_selection import train_test_split\nfrom sklearn import metrics\nfrom sklearn.metrics import confusion_matrix","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:18.347167Z","iopub.execute_input":"2021-08-02T19:50:18.347523Z","iopub.status.idle":"2021-08-02T19:50:19.333087Z","shell.execute_reply.started":"2021-08-02T19:50:18.347494Z","shell.execute_reply":"2021-08-02T19:50:19.332414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:19.334064Z","iopub.execute_input":"2021-08-02T19:50:19.334406Z","iopub.status.idle":"2021-08-02T19:50:19.339667Z","shell.execute_reply.started":"2021-08-02T19:50:19.334381Z","shell.execute_reply":"2021-08-02T19:50:19.338974Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/digit-recognizer/train.csv\")\ntest = pd.read_csv(\"/kaggle/input/digit-recognizer/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:19.341270Z","iopub.execute_input":"2021-08-02T19:50:19.341673Z","iopub.status.idle":"2021-08-02T19:50:24.678334Z","shell.execute_reply.started":"2021-08-02T19:50:19.341647Z","shell.execute_reply":"2021-08-02T19:50:24.677590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.isnull().sum()","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:24.679649Z","iopub.execute_input":"2021-08-02T19:50:24.679913Z","iopub.status.idle":"2021-08-02T19:50:24.740546Z","shell.execute_reply.started":"2021-08-02T19:50:24.679888Z","shell.execute_reply":"2021-08-02T19:50:24.739823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.describe()","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:24.741644Z","iopub.execute_input":"2021-08-02T19:50:24.741948Z","iopub.status.idle":"2021-08-02T19:50:26.810591Z","shell.execute_reply.started":"2021-08-02T19:50:24.741924Z","shell.execute_reply":"2021-08-02T19:50:26.809814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.unique(train['label'])","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:26.811797Z","iopub.execute_input":"2021-08-02T19:50:26.812062Z","iopub.status.idle":"2021-08-02T19:50:26.818740Z","shell.execute_reply.started":"2021-08-02T19:50:26.812038Z","shell.execute_reply":"2021-08-02T19:50:26.817990Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"number=train.iloc[106, 1:]\nnumber=number.values.reshape(28,28)\npt.imshow(number)","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:26.819916Z","iopub.execute_input":"2021-08-02T19:50:26.820161Z","iopub.status.idle":"2021-08-02T19:50:26.977468Z","shell.execute_reply.started":"2021-08-02T19:50:26.820140Z","shell.execute_reply":"2021-08-02T19:50:26.976582Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(train.corr())","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:50:26.979339Z","iopub.execute_input":"2021-08-02T19:50:26.979615Z","iopub.status.idle":"2021-08-02T19:51:29.126337Z","shell.execute_reply.started":"2021-08-02T19:50:26.979588Z","shell.execute_reply":"2021-08-02T19:51:29.125699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train.drop(\"label\", axis = 1)\ny = train['label']","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:51:29.127336Z","iopub.execute_input":"2021-08-02T19:51:29.127637Z","iopub.status.idle":"2021-08-02T19:51:29.205434Z","shell.execute_reply.started":"2021-08-02T19:51:29.127615Z","shell.execute_reply":"2021-08-02T19:51:29.204569Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_scaled = scale(X)\nX_train, X_test, y_train, y_test = train_test_split(X_scaled, y, train_size=0.3,test_size = 0.7, random_state = 101)","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:51:29.206643Z","iopub.execute_input":"2021-08-02T19:51:29.206935Z","iopub.status.idle":"2021-08-02T19:51:30.623008Z","shell.execute_reply.started":"2021-08-02T19:51:29.206907Z","shell.execute_reply":"2021-08-02T19:51:30.622227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_linear = svm.SVC(kernel='linear')\nmodel_linear.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:51:30.624097Z","iopub.execute_input":"2021-08-02T19:51:30.624347Z","iopub.status.idle":"2021-08-02T19:51:55.076589Z","shell.execute_reply.started":"2021-08-02T19:51:30.624318Z","shell.execute_reply":"2021-08-02T19:51:55.075825Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model_linear.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:51:55.077597Z","iopub.execute_input":"2021-08-02T19:51:55.077855Z","iopub.status.idle":"2021-08-02T19:53:35.434139Z","shell.execute_reply.started":"2021-08-02T19:51:55.077831Z","shell.execute_reply":"2021-08-02T19:53:35.433280Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(metrics.accuracy_score(y_true=y_test, y_pred=y_pred))","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:53:35.435374Z","iopub.execute_input":"2021-08-02T19:53:35.435764Z","iopub.status.idle":"2021-08-02T19:53:35.444772Z","shell.execute_reply.started":"2021-08-02T19:53:35.435715Z","shell.execute_reply":"2021-08-02T19:53:35.443810Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub=model_linear.predict(test)\nsub\n\"\"\"dp = pd.read_csv(\"/kaggle/input/digit-recognizer/sample_submission.csv\")\ndp[\"Label\"] = sub\ndp.to_csv(\"sample_submission.csv\", index=False)\"\"\"","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:53:35.446209Z","iopub.execute_input":"2021-08-02T19:53:35.446661Z","iopub.status.idle":"2021-08-02T19:55:12.048545Z","shell.execute_reply.started":"2021-08-02T19:53:35.446623Z","shell.execute_reply":"2021-08-02T19:55:12.047691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub","metadata":{"execution":{"iopub.status.busy":"2021-08-02T19:55:21.036818Z","iopub.execute_input":"2021-08-02T19:55:21.037133Z","iopub.status.idle":"2021-08-02T19:55:21.042594Z","shell.execute_reply.started":"2021-08-02T19:55:21.037107Z","shell.execute_reply":"2021-08-02T19:55:21.041658Z"},"trusted":true},"execution_count":null,"outputs":[]}]}