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?
CodePudding user response:
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:
- https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_score.html#sklearn.metrics.precision_score
- https://scikit-learn.org/stable/modules/generated/sklearn.metrics.recall_score.html#sklearn.metrics.recall_score
- https://scikit-learn.org/stable/auto_examples/model_selection/plot_precision_recall.html
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)