0

how I can calculate the prediction Accuracy and F1 Score of OneVsRestClassifier?

>>> 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)
RJFF
  • 37
  • 1
  • 5
  • @FlorianH see [Possible duplicate question in another (programming) language](https://meta.stackoverflow.com/q/319542/3005167) – MB-F Sep 05 '19 at 10:22
  • @kazemakase Thanks, i missed that, removed the possible dublicate. – Florian H Sep 05 '19 at 10:53
  • Possible duplicate of [Accuracy, precision, and recall for multi-class model](https://stackoverflow.com/questions/33081702/accuracy-precision-and-recall-for-multi-class-model) – greg-449 Sep 05 '19 at 11:10
  • Before rushing to open a question here, please ensure that at least you have read the relevant [documentation](https://scikit-learn.org/stable/modules/classes.html#module-sklearn.metrics) – desertnaut Sep 05 '19 at 12:23

1 Answers1

2

You can use sklearn's metrics module.

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'))

Note that I set the average argument to micro. You can change this based on the options here.

Kyle
  • 461
  • 3
  • 13