What are all the valid strings I can use with keras.model.compile?

Question:

What strings are valid metrics with keras.model.compile?

The following works,

model.compile(optimizer='sgd', loss='mse', metrics=['acc'])

but this does not work,

model.compile(optimizer='sgd', loss='mse', metrics=['recall', 'precision'])
Asked By: John Henckel

||

Answers:

See keras source code, the list of metrics is

  • accuracy
  • binary_accuracy
  • categorical_accuracy
  • sparse_categorical_accuracy
  • top_k_categorical_accuracy
  • sparse_top_k_categorical_accuracy
  • cosine_similarity
  • binary_crossentropy
  • categorical_crossentropy
  • categorical_hinge
  • hinge
  • squared_hinge
  • kullback_leibler_divergence
  • logcosh
  • mean_absolute_error
  • mean_absolute_percentage_error
  • mean_squared_error
  • mean_squared_logarithmic_error
  • poisson
  • sparse_categorical_crossentropy

Possible abbreviations:

  • acc = ACC = accuracy
  • bce = BCE = binary_crossentropy
  • mse = MSE = mean_squared_error
  • mae = MAE = mean_absolute_error
  • mape = MAPE = mean_absolute_percentage_error
  • msle = MSLE = mean_squared_logarithmic_error
  • log_cosh = logcosh
  • cosine_proximity = cosine_similarity

any others will need to be added as custom objects, see this link

Answered By: John Henckel

Check method to check metrices. Check docstring for details

enter image description here

Answered By: Abhishek
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.