Search code examples
pythonmachine-learningkerasdeep-learningmlp

Get the recall over the epochs in keras


I am compiling my model with

metrics=["accuracy", keras.metrics.Recall()]

as stated in the documentation. But when I try to obtain it after I've trained my model I get a key_error "recall". Both versions,

recall = estimator_bio.history["Recall"]
recall = estimator_bio.history["recall"]

result in

KeyError: 'Recall'

While

accuracies = estimator_bio.history["accuracy"]

works. What is the keyword for the recall?


Solution

  • You can always pass a name to the metric:

    metrics=["accuracy", keras.metrics.Recall(name='recall')]
    

    this way you can reference it in an easy way.

    Anyway you should print or inspect the contents of the history object to see what it contains and the actual key/name assigned to Recall (which by the way should be recall).

    Usually what you do is:

    # Fit the model
    history = model.fit(.....)
    # and then you can see what is available in the history with:
    print(history.history.keys())