from keras.models import Sequential
from keras.layers import Dense, Activation
# Simple feed-forward architecture
model = Sequential()
model.add(Dense(output_dim=64, input_dim=100))
model.add(Activation("relu"))
model.add(Dense(output_dim=10))
model.add(Activation("softmax"))
# Optimize with SGD (learning process)
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
# iterate training data in batches
model.fit(X_train, Y_train, nb_epoch=5, batch_size=32)
# alternatively feed in training data in one batch model.train_on_batch(x_batch, y_batch)
# Evaluate model
loss_and_metrics = model.evaluate(X_test, Y_test, batch_size=32)
# create predicitions on new data
classes = model.predicts(X_test, batch_size=32)
|