RMSE/ RMSLE loss function in Keras RMSE/ RMSLE loss function in Keras python python

RMSE/ RMSLE loss function in Keras


When you use a custom loss, you need to put it without quotes, as you pass the function object, not a string:

def root_mean_squared_error(y_true, y_pred):        return K.sqrt(K.mean(K.square(y_pred - y_true))) model.compile(optimizer = "rmsprop", loss = root_mean_squared_error,               metrics =["accuracy"])


The accepted answer contains an error, which leads to that RMSE being actually MAE, as per the following issue:

https://github.com/keras-team/keras/issues/10706

The correct definition should be

def root_mean_squared_error(y_true, y_pred):        return K.sqrt(K.mean(K.square(y_pred - y_true)))


If you are using latest tensorflow nightly, although there is no RMSE in the documentation, there is a tf.keras.metrics.RootMeanSquaredError() in the source code.

sample usage:

model.compile(tf.compat.v1.train.GradientDescentOptimizer(learning_rate),              loss=tf.keras.metrics.mean_squared_error,              metrics=[tf.keras.metrics.RootMeanSquaredError(name='rmse')])