머신러닝스터디/2016
머신러닝스터디/2016/목차

내용

코드

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)

후기

  • 서지혜: 맥에어에서 돌렸더니 엄청 오래걸렸다.. 클라우드 세팅해야될거같음. 아래는 결과물. 다 돌리고 출력을 어떻게 해야할지 모르겠네.

Using Theano backend.
Epoch 1/3
60000/60000 [==============================] - 3122s - loss: 14.4306 - acc: 0.1047     
Epoch 2/3
60000/60000 [==============================] - 3055s - loss: 14.4370 - acc: 0.1043     
Epoch 3/3
60000/60000 [==============================] - 3135s - loss: 14.4453 - acc: 0.1038     

10000/10000 [==============================] - 398s
[14.461154937744141, 0.10279999673366547]

다음 시간에는

  • Week 6 보기

더 보기

Retrieved from http://wiki.zeropage.org/wiki.php/머신러닝스터디/2016/2016_06_11
last modified 2021-02-07 05:29:27