如何计算OneVsRestClassifier的预测准确性和F1得分?
>>> from sklearn import datasets
>>> from sklearn.multiclass import OneVsRestClassifier
>>> from sklearn.svm import LinearSVC
>>> iris = datasets.load_iris()
>>> X, y = iris.data, iris.target
>>> OneVsRestClassifier(LinearSVC(random_state=0)).fit(X, y).predict(X)
答案 0 :(得分:0)
您可以使用sklearn的指标模块。
from sklearn import datasets
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import LinearSVC
from sklearn.metrics import accuracy_score, f1_score
iris = datasets.load_iris()
X, y = iris.data, iris.target
model = OneVsRestClassifier(LinearSVC(random_state=0))
model.fit(X, y)
yhat = model.predict(X)
print('Accuracy:', accuracy_score(y, yhat))
print('F1:', f1_score(y, yhat, average='micro'))
请注意,我将average
参数设置为micro
。您可以根据选项here进行更改。