Skip to content

Instantly share code, notes, and snippets.

@Joelfranklin96
Created December 10, 2019 21:08
Show Gist options
  • Save Joelfranklin96/f2caa525436cd4b94db04f6283edff73 to your computer and use it in GitHub Desktop.
Save Joelfranklin96/f2caa525436cd4b94db04f6283edff73 to your computer and use it in GitHub Desktop.
Training model using optimum values of hyperparameters
from sklearn.metrics import classification_report, accuracy_score
# Defining the model
def create_model():
model = Sequential()
model.add(Dense(16,input_dim = 8,kernel_initializer = 'uniform',activation = 'tanh'))
model.add(Dropout(0.1))
model.add(Dense(4,input_dim = 16,kernel_initializer = 'uniform',activation = 'tanh'))
model.add(Dropout(0.1))
model.add(Dense(1,activation = 'sigmoid'))
adam = Adam(lr = 0.001)
model.compile(loss = 'binary_crossentropy',optimizer = adam,metrics = ['accuracy'])
return model
# Create the model
model = KerasClassifier(build_fn = create_model,verbose = 0,batch_size = 40,epochs = 10)
# Fitting the model
model.fit(X_standardized,y)
# Predicting using trained model
y_predict = model.predict(X_standardized)
# Printing the metrics
print(accuracy_score(y,y_predict))
print(classification_report(y,y_predict))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment