Skip to content

Instantly share code, notes, and snippets.

@KhyatiMahendru
Last active November 16, 2021 08:17
Show Gist options
  • Save KhyatiMahendru/a186690d3f8018920b135e1b4b5d71c4 to your computer and use it in GitHub Desktop.
Save KhyatiMahendru/a186690d3f8018920b135e1b4b5d71c4 to your computer and use it in GitHub Desktop.
# importing requirements
from keras.layers import Dense
from keras.models import Sequential
from keras.optimizers import adam
# alpha = 0.001 as given in the lr parameter in adam() optimizer
# build the model
model_alpha1 = Sequential()
model_alpha1.add(Dense(50, input_dim=2, activation='relu'))
model_alpha1.add(Dense(3, activation='softmax'))
# compile the model
opt_alpha1 = adam(lr=0.001)
model_alpha1.compile(loss='kullback_leibler_divergence', optimizer=opt_alpha1, metrics=['accuracy'])
# fit the model
# dummy_Y is the one-hot encoded
# history_alpha1 is used to score the validation and accuracy scores for plotting
history_alpha1 = model_alpha1.fit(dataX, dummy_Y, validation_data=(dataX, dummy_Y), epochs=200, verbose=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment