U E D R , A S I H C RSS

머신러닝스터디/2016/2016_06_11 (rev. 1.4)

머신러닝스터디/2016/2016_06_11

내용

코드

from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation
from keras.datasets import mnist
from keras.layers.core import Reshape
import numpy as np

(X_train, y_train), (X_test, y_test) = mnist.load_data()

model = Sequential()
model.add(Reshape((28*28,), input_shape=(28,28)))
model.add(Dense(60000, input_dim=28*28, activation='relu'))

model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))

model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))

model.compile(loss='categorical_crossentropy',
              optimizer='adagrad',
              metrics=['accuracy'])

# y_train and y_test is simple integer of 0 to 9
# Need to be transformed to array
y_train_array = np.zeros((60000, 10))
y_test_array = np.zeros((10000, 10))
for i in range(60000):
  y_train_array[i][y_train[i]] = 1
for i in range(10000):
  y_test_array[i][y_test[i]] = 1

model.fit(X_train, y_train_array,
          nb_epoch=3,
          batch_size=16)

score = model.evaluate(X_test, y_test_array, batch_size=10000)

# TODO
print(score)

후기

다음 시간에는

  • Week 6 보기
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:27
Processing time 0.0360 sec