Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add precision and recall in return eval_model #172

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions medcat/utils/meta_cat/ml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from scipy.special import softmax
from sklearn.metrics import classification_report, f1_score
from sklearn.metrics import classification_report, f1_score, precision_recall_fscore_support
from torch import nn
import torch.optim as optim

Expand Down Expand Up @@ -258,7 +258,7 @@ def eval_model(model, data, config, tokenizer):

score_average = config.train['score_average']
predictions = np.argmax(np.concatenate(all_logits, axis=0), axis=1)
f1 = f1_score(y_eval, predictions, average=score_average)
precision, recall, f1, support = precision_recall_fscore_support(y_eval, predictions, average=score_average)

examples = {'FP': {}, 'FN': {}, 'TP': {}}
id2category_value = {v: k for k, v in config.general['category_value2id'].items()}
Expand All @@ -277,4 +277,4 @@ def eval_model(model, data, config, tokenizer):
else:
examples['TP'][y] = examples['TP'].get(y, []) + [(info, text)]

return {'f1': f1, 'examples': examples}
return {'precision': precision, 'recall': recall, 'f1': f1, 'examples': examples}