{"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":"markdown","source":"# Изображения рукописных цифр (MNIST dataset)","metadata":{"_cell_guid":"3b128fa5-c4fa-257e-550c-0bf8f077780c"}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom sklearn.svm import SVC\nfrom sklearn import decomposition, preprocessing\nfrom sklearn.model_selection import train_test_split\nfrom sklearn import metrics\nimport matplotlib.pyplot as plt\n%matplotlib inline","metadata":{"_cell_guid":"5e106a8e-1337-60c6-3904-dc016ffb2afb","execution":{"iopub.status.busy":"2021-09-15T17:19:35.703592Z","iopub.execute_input":"2021-09-15T17:19:35.704642Z","iopub.status.idle":"2021-09-15T17:19:36.733472Z","shell.execute_reply.started":"2021-09-15T17:19:35.704519Z","shell.execute_reply":"2021-09-15T17:19:36.732566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Импорт и обзор данных","metadata":{}},{"cell_type":"code","source":"df = pd.read_csv(\"../input/train.csv\")\n\nX = df.values[:,1:]\nY = df.values[:,0]  # The first column contains digits labels","metadata":{"_cell_guid":"14e33880-2fb4-5e82-f2ba-843301af5d73","execution":{"iopub.status.busy":"2021-09-15T17:19:36.735146Z","iopub.execute_input":"2021-09-15T17:19:36.735377Z","iopub.status.idle":"2021-09-15T17:19:40.435433Z","shell.execute_reply.started":"2021-09-15T17:19:36.735351Z","shell.execute_reply":"2021-09-15T17:19:40.434496Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pics = X.reshape(-1, 28, 28, 1)\nplt.imshow(pics[523][:,:,0])","metadata":{"execution":{"iopub.status.busy":"2021-09-15T17:19:40.436502Z","iopub.execute_input":"2021-09-15T17:19:40.436718Z","iopub.status.idle":"2021-09-15T17:19:40.673834Z","shell.execute_reply.started":"2021-09-15T17:19:40.436692Z","shell.execute_reply":"2021-09-15T17:19:40.672911Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = decomposition.PCA(n_components = 0.8, whiten = True)\nX = pca.fit_transform(X)\n\nX_train, X_test, y_train, y_test = train_test_split(X, Y, test_size = 0.2, random_state = 42)","metadata":{"_cell_guid":"64e17d6b-632e-b031-b63c-1eea290d9be9","execution":{"iopub.status.busy":"2021-09-15T17:19:40.674976Z","iopub.execute_input":"2021-09-15T17:19:40.675638Z","iopub.status.idle":"2021-09-15T17:19:46.004224Z","shell.execute_reply.started":"2021-09-15T17:19:40.675603Z","shell.execute_reply":"2021-09-15T17:19:46.003517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Классификация","metadata":{"_cell_guid":"57608def-493f-4dfb-f171-210241d34473"}},{"cell_type":"code","source":"model = SVC()\n\nmodel.fit(X_train, y_train)\nprediction = model.predict(X_test)\naccuracy = metrics.accuracy_score(prediction, y_test)\n\nprint(f\"Точность классификации:\", accuracy)  # 0.978","metadata":{"_cell_guid":"3d566231-a576-716c-031a-e1d87e7a7cf8","execution":{"iopub.status.busy":"2021-09-15T17:19:46.006428Z","iopub.execute_input":"2021-09-15T17:19:46.006786Z","iopub.status.idle":"2021-09-15T17:20:20.455895Z","shell.execute_reply.started":"2021-09-15T17:19:46.006745Z","shell.execute_reply":"2021-09-15T17:20:20.455027Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}