MNIST-数据集准备

时间:2018-10-23 09:16:20

标签: python pandas machine-learning

我正在研究用于机器学习的MNIST数据集,并且我有2个csv文件。一个包含数据,另一个包含标签(从0到9)。 如何重塑形状并添加标签,以便可以将其用于机器学习预测?

enter image description here(标签) enter image description here(图片)

1 个答案:

答案 0 :(得分:0)

我认为您需要这个:

from keras.datasets import mnist
from keras import models
from keras import layers

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()
train_images = train_images.rashape((60000, 28*28))
train_labels = train_images.astype('float32') / 255
test_images = test_images.rashape((10000, 28*28))
test_labels = test_images.astype('float32') / 255

network = models.Sequential()
network.add(layers.Dense(512, activation='relu', input_shape=(28*28,)))
network.add(layers.Dense(10, activation='softmax'))
network.compile(optimizer='rmsprop', loss='categorical_crossentropy', metrics=['accuracy'])
network.fit(train_images, train_labels, epochs=5, batch_size=128)