簡體   English   中英

MNIST - 數據集准備

[英]MNIST - dataset preparation

我正在研究用於機器學習的 MNIST 數據集,並且我有 2 個 csv 文件。 一個包含數據,另一個包含標簽(從 0 到 9)。 如何重塑和添加標簽,以便我可以將其用於機器學習預測?

在此處輸入圖像描述(標簽)在此處輸入圖像描述(圖像)

我認為你需要這個:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM