Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # import model base and layers
  2. from keras.models import Sequential
  3. from keras.layers import Dense
  4.  
  5. def twoLayerFeedForward():
  6. # stack the layers
  7. clf = Sequential()
  8. clf.add(Dense(9, activation='relu', input_dim=3))
  9. clf.add(Dense(9, activation='relu'))
  10. clf.add(Dense(3, activation='softmax'))
  11. # compile the model
  12. clf.compile(
  13. loss='categorical_crossentropy', optimizer=SGD(),
  14. metrics=["accuracy"]
  15. )
  16. return clf
  17.  
  18. # initialize the model object
  19. model = twoLayerFeedForward()
  20.  
  21. # call fit to train the model
  22. # notice how hyper-parameters are set at fit, not at init
  23. model.fit(
  24. X, y, epochs=50, batch_size=256,
  25. validation_data=(X_test, X_test)
  26. )
  27.  
  28. # call predict to get predictions
  29. y_pred = model.predict(X)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement