官术网_书友最值得收藏!

Precision, recall, and F1-score

To assess the quality of the algorithm considering the two types of error, accuracy metric is useless. That's why different metrics were proposed.

Precision and recall are metrics used to evaluate a prediction's quality in information retrieval and binary classification. Precision is a proportion of true positives among all predicted positives. It shows how relevant results are. Recall, also known as sensitivity, is a proportion of true positives among all truly positive samples. For example, if the task is to distinguish cat photos from non-cat photos, precision is a fraction of correctly predicted cats to all predicted cats. Recall is a fraction of predicted cats to the total number of true cats.

If we denote the number of true positive cases as Tp, and number of false positive cases as Fp, then precision P is calculated as:

Recall R is calculated as:

,

Where Fn is a number of false negative cases.

F1 measure is calculated as:

Now the same in Python:

In []: 
import numpy as np 
predictions = tree_model.predict(X_test) 
predictions = np.array(map(lambda x: x == 'rabbosaurus', predictions), dtype='int') 
true_labels = np.array(map(lambda x: x == 'rabbosaurus', y_test), dtype='int') 
from sklearn.metrics import precision_score, recall_score, f1_score 
precision_score(true_labels, predictions) 
Out[]: 
0.87096774193548387 
In []: 
recall_score(true_labels, predictions) 
Out[]: 
0.88815789473684215 
In []: 
f1_score(true_labels, predictions) 
Out[]: 
0.87947882736156346 
主站蜘蛛池模板: 上饶市| 闽侯县| 滕州市| 衡东县| 丰县| 临沂市| 新龙县| 汝城县| 锦屏县| 吉首市| 丰城市| 博爱县| 吉林省| 呼伦贝尔市| 镇雄县| 南通市| 旬阳县| 林州市| 巍山| 古蔺县| 宁武县| 佛冈县| 襄汾县| 洪泽县| 定西市| 铜陵市| 津市市| 德钦县| 彰武县| 全州县| 龙胜| 赤城县| 武汉市| 沧州市| 嫩江县| 岑巩县| 伽师县| 辽阳市| 闵行区| 确山县| 连州市|