Search code examples
tensorflowkerasprecision-recall

Computing Precision and Recall after training a model


I have trained/fine-tuned a few Keras models and during that, I used 'accuracy' as the only metric to calculate. now after training everything which took a long time, I realized I need precision and recall. Is there a chance I have extract/compute that information after the training is finished with the saved model and the accuracies at hand?


Solution

  • You can apply the trained model on the test set, generate a list of the true labels and predicted labels, and then use the score metrics from scikit-learn. See documentation here:

    For example, for a binary classification problem:

    
    from sklearn.metrics import precision_score
    
    # I assume y_true are the list of true labels of the test set
    # I assume y_pred are the predictions of the model
    precision = precision_score(y_true, y_pred)
    recall = recall_score(y_true, y_pred)