Skip to content

Instantly share code, notes, and snippets.

@ResidentMario
Created March 14, 2019 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ResidentMario/09c56d6ea1dbb342aabeaaa0b7e19713 to your computer and use it in GitHub Desktop.
Save ResidentMario/09c56d6ea1dbb342aabeaaa0b7e19713 to your computer and use it in GitHub Desktop.
# import model base and layers
from keras.models import Sequential
from keras.layers import Dense
def twoLayerFeedForward():
# stack the layers
clf = Sequential()
clf.add(Dense(9, activation='relu', input_dim=3))
clf.add(Dense(9, activation='relu'))
clf.add(Dense(3, activation='softmax'))
# compile the model
clf.compile(
loss='categorical_crossentropy', optimizer=SGD(),
metrics=["accuracy"]
)
return clf
# initialize the model object
model = twoLayerFeedForward()
# call fit to train the model
# notice how hyper-parameters are set at fit, not at init
model.fit(
X, y, epochs=50, batch_size=256,
validation_data=(X_test, X_test)
)
# call predict to get predictions
y_pred = model.predict(X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment