U E D R , A S I H C RSS

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

내용

코드

import pandas as pd
import keras
from sklearn.cross_validation import train_test_split
from keras.utils.np_utils import to_categorical

train = pd.read_csv("../input/train.csv")
test  = pd.read_csv("../input/test.csv")

y_train = train['label'].as_matrix()
X_train = train.drop('label', axis=1).as_matrix()

X_train, X_test, y_train, y_test = train_test_split(X_train/255., y_train, test_size=0.30)

model = keras.models.Sequential()

model.add(keras.layers.Dense(64, input_dim=28*28, activation='relu'))
model.add(keras.layers.Dense(32, activation='relu'))
model.add(keras.layers.Dense(16, activation='relu'))
model.add(keras.layers.Dense(10, activation='softmax'))

model.compile(loss='categorical_crossentropy', optimizer='adagrad', metrics=['accuracy'])
model.fit(X_train, to_categorical(y_train, 10), nb_epoch=5, batch_size=600)

score = model.evaluate(X_test, to_categorical(y_test, 10), batch_size=700)

print(score)

print(model.predict(X_test))[0]
print(y_test[0])

다음 시간에는

  • 한 주 쉬어갑니다.
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:27
Processing time 0.0123 sec