Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

keras

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'])
like image 255
John Henckel Avatar asked Oct 14 '25 15:10

John Henckel


2 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

like image 186
John Henckel Avatar answered Oct 17 '25 06:10

John Henckel


Check method to check metrices. Check docstring for details

enter image description here

like image 29
Abhishek Avatar answered Oct 17 '25 04:10

Abhishek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!