Created
November 8, 2019 04:46
-
-
Save analyticsindiamagazine/dcbbaba6253d94c618320ab73644b24e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A function that trains and validates the model and returns the rmse | |
def train_test_model(hparams): | |
#Keras sequential model with Hyperparameters passed from the argument | |
model = tf.keras.models.Sequential([ | |
tf.keras.layers.InputLayer(input_shape = 26), | |
tf.keras.layers.Dense(hparams[HP_NUM_UNITS], activation=tf.nn.relu, kernel_initializer = 'uniform'), | |
tf.keras.layers.Dropout(hparams[HP_DROPOUT]), | |
tf.keras.layers.Dense(1), | |
]) | |
#Compiling the model | |
model.compile( | |
optimizer=hparams[HP_OPTIMIZER], | |
loss='mean_squared_logarithmic_error', | |
metrics=['RootMeanSquaredError'], | |
) | |
#Training the network | |
model.fit(x_train, y_train, epochs=6) | |
_, rmse = model.evaluate(x_test, y_test) | |
return rmse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment