简体   繁体   中英

How to Calculate Precision, Recall, and F1 for Entity Prediction

I used an Entity Linking Model from Github to predict a set of documents. Since they do not actually explain how to calculate precision, recall, and F1. So I created a dataframe by using the actual tag and predict tag from the testing data.

 Actual           Predict
security          security
london             london
  UK                 US
  :                   :
  :                   :
domain              menu
sushi               soso
tom                jerry

I am wondering based on this, will I be able to calculate the precision, recall, and f1 on my own and if I can, how can I do it? Thanks!

I assume that you have the value of y_test then you may have y_pred according with your prediction.

Calculating the precision, recall, and fscore are able using these library from sklearn.metrics import precision_score, recall_score, f1_score

calculate metrics

import sklearn
from sklearn.metrics import precision_score, recall_score, f1_score
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1_score = f1_score(y_test, y_pred)

i got it from https://machinelearningmastery.com/precision-recall-and-f-measure-for-imbalanced-classification/ https://machinelearningmastery.com/how-to-calculate-precision-recall-f1-and-more-for-deep-learning-models/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM