[英]Scipy/Numpy/scikits - calculating precision/recall scores based on two arrays
import scikits as sklearn from sklearn.linear_model import LogisticRegression lr = LogisticRegression(C=0.1, penalty='l1') model = lr.fit(training[:,0:-1], training[:,-1)
cv[:,-1]
CV [:, - 1]
cv_predict = model.predict(cv[:,0:-1])
cv_predict = model.predict(cv [:,0:-1])
Question 题
I want to calculate the precision and recall scores based on acutal labels and predicted labels. 我想根据实际标签和预测标签计算精度和召回分数。 Is there a standard method to do it using numpy/scipy/scikits?
是否有标准的方法来使用numpy / scipy / scikits?
Thank you 谢谢
Yes there are, see the documentation: http://scikit-learn.org/stable/modules/classes.html#classification-metrics 是的,请参阅文档: http : //scikit-learn.org/stable/modules/classes.html#classification-metrics
You should also have a look at the sklearn.metrics.classification_report
utility: 您还应该查看
sklearn.metrics.classification_report
实用程序:
>>> from sklearn.metrics import classification_report
>>> from sklearn.linear_model import SGDClassifier
>>> from sklearn.datasets import load_digits
>>> digits = load_digits()
>>> n_samples, n_features = digits.data.shape
>>> n_split = n_samples / 2
>>> clf = SGDClassifier().fit(digits.data[:n_split], digits.target[:n_split])
>>> predictions = clf.predict(digits.data[n_split:])
>>> expected = digits.target[n_split:]
>>> print classification_report(expected, predictions)
precision recall f1-score support
0 0.90 0.98 0.93 88
1 0.81 0.69 0.75 91
2 0.94 0.98 0.96 86
3 0.94 0.85 0.89 91
4 0.90 0.93 0.91 92
5 0.92 0.92 0.92 91
6 0.92 0.97 0.94 91
7 1.00 0.85 0.92 89
8 0.71 0.89 0.79 88
9 0.89 0.83 0.86 92
avg / total 0.89 0.89 0.89 899
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.