Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

4.5 KiB

#пункт 1
import os
os.chdir('/content/drive/MyDrive/Colab Notebooks')
# импорт модулей
from tensorflow import keras
import matplotlib.pyplot as plt
import numpy as np
import sklearn

#пункт 2
# загрузка датасета
from keras.datasets import mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()

#пункт 3
# создание своего разбиения датасета
from sklearn.model_selection import train_test_split
# объединяем в один набор
X = np.concatenate((X_train, X_test))
y = np.concatenate((y_train, y_test))
# разбиваем по вариантам
X_train, X_test, y_train, y_test = train_test_split(X, y,
 test_size = 10000,
 train_size = 60000,
 random_state = 123)
# вывод размерностей
print('Shape of X train:', X_train.shape)
print('Shape of y train:', y_train.shape)

#пункт 4
# вывод изображения 1
plt.imshow(X_train[0], cmap=plt.get_cmap('gray'))
plt.show()
# вывод метки для этого изображения
print(y_train[0])
# вывод изображения 2
plt.imshow(X_train[1], cmap=plt.get_cmap('gray'))
plt.show()
# вывод метки для этого изображения
print(y_train[1])
# вывод изображения 3
plt.imshow(X_train[2], cmap=plt.get_cmap('gray'))
plt.show()
# вывод метки для этого изображения
print(y_train[2])
# вывод изображения 4
plt.imshow(X_train[3], cmap=plt.get_cmap('gray'))
plt.show()
# вывод метки для этого изображения
print(y_train[3])


#пункт 5
# развернем каждое изображение 28*28 в вектор 784
num_pixels = X_train.shape[1] * X_train.shape[2]
X_train = X_train.reshape(X_train.shape[0], num_pixels) / 255
X_test = X_test.reshape(X_test.shape[0], num_pixels) / 255
print('Shape of transformed X train:', X_train.shape)

# переведем метки в one-hot

from keras.utils import np_utils
y_train = np_utils.to_categorical(y_train)
y_test = np_utils.to_categorical(y_test)
print('Shape of transformed y train:', y_train.shape)
num_classes = y_train.shape[1]

print('Shape of transformed X test:', X_test.shape)
print('Shape of transformed Y test:', y_test.shape)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/tmp/ipython-input-1074595868.py in <cell line: 0>()
      1 #пункт 1
      2 import os
----> 3 os.chdir('/content/drive/MyDrive/Colab Notebooks')
      4 # импорт модулей
      5 from tensorflow import keras

FileNotFoundError: [Errno 2] No such file or directory: '/content/drive/MyDrive/Colab Notebooks'