{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyPC/SZVlsvuucft1t0l8Bhx"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"id":"lXNlZGHIqxlV","executionInfo":{"status":"error","timestamp":1758531901705,"user_tz":-180,"elapsed":50,"user":{"displayName":"Данила Новиков","userId":"16029008369036023959"}},"outputId":"a6271035-c2c2-40e1-e2cd-c4cee8035df6","colab":{"base_uri":"https://localhost:8080/","height":211}},"outputs":[{"output_type":"error","ename":"FileNotFoundError","evalue":"[Errno 2] No such file or directory: '/content/drive/MyDrive/Colab Notebooks'","traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mFileNotFoundError\u001b[0m                         Traceback (most recent call last)","\u001b[0;32m/tmp/ipython-input-1074595868.py\u001b[0m in \u001b[0;36m<cell line: 0>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m#пункт 1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      2\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mchdir\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'/content/drive/MyDrive/Colab Notebooks'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      4\u001b[0m \u001b[0;31m# импорт модулей\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      5\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mtensorflow\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mkeras\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '/content/drive/MyDrive/Colab Notebooks'"]}],"source":["#пункт 1\n","import os\n","os.chdir('/content/drive/MyDrive/Colab Notebooks')\n","# импорт модулей\n","from tensorflow import keras\n","import matplotlib.pyplot as plt\n","import numpy as np\n","import sklearn\n","\n","#пункт 2\n","# загрузка датасета\n","from keras.datasets import mnist\n","(X_train, y_train), (X_test, y_test) = mnist.load_data()\n","\n","#пункт 3\n","# создание своего разбиения датасета\n","from sklearn.model_selection import train_test_split\n","# объединяем в один набор\n","X = np.concatenate((X_train, X_test))\n","y = np.concatenate((y_train, y_test))\n","# разбиваем по вариантам\n","X_train, X_test, y_train, y_test = train_test_split(X, y,\n"," test_size = 10000,\n"," train_size = 60000,\n"," random_state = 123)\n","# вывод размерностей\n","print('Shape of X train:', X_train.shape)\n","print('Shape of y train:', y_train.shape)\n","\n","#пункт 4\n","# вывод изображения 1\n","plt.imshow(X_train[0], cmap=plt.get_cmap('gray'))\n","plt.show()\n","# вывод метки для этого изображения\n","print(y_train[0])\n","# вывод изображения 2\n","plt.imshow(X_train[1], cmap=plt.get_cmap('gray'))\n","plt.show()\n","# вывод метки для этого изображения\n","print(y_train[1])\n","# вывод изображения 3\n","plt.imshow(X_train[2], cmap=plt.get_cmap('gray'))\n","plt.show()\n","# вывод метки для этого изображения\n","print(y_train[2])\n","# вывод изображения 4\n","plt.imshow(X_train[3], cmap=plt.get_cmap('gray'))\n","plt.show()\n","# вывод метки для этого изображения\n","print(y_train[3])\n","\n","\n","#пункт 5\n","# развернем каждое изображение 28*28 в вектор 784\n","num_pixels = X_train.shape[1] * X_train.shape[2]\n","X_train = X_train.reshape(X_train.shape[0], num_pixels) / 255\n","X_test = X_test.reshape(X_test.shape[0], num_pixels) / 255\n","print('Shape of transformed X train:', X_train.shape)\n","\n","# переведем метки в one-hot\n","\n","from keras.utils import np_utils\n","y_train = np_utils.to_categorical(y_train)\n","y_test = np_utils.to_categorical(y_test)\n","print('Shape of transformed y train:', y_train.shape)\n","num_classes = y_train.shape[1]\n","\n","print('Shape of transformed X test:', X_test.shape)\n","print('Shape of transformed Y test:', y_test.shape)\n"]}]}