Python : How to find Accuracy Result in SVM Text Classifier Algorithm for Multilabel Class

ⅰ亾dé卋堺 提交于 2019-12-03 03:04:08
mayhewsw

If you want to get an accuracy score for your test set, you'll need to create an answer key, which you can call y_test. You can't know if your predictions are correct unless you know the correct answers.

Once you have an answer key, you can get the accuracy. The method you want is sklearn.metrics.accuracy_score.

I've written it out below:

from sklearn.metrics import accuracy_score

# ... everything else the same ...

# create an answer key
# I hope this is correct!
y_test = [[1], [2], [3]]

# same as yours...
classifier.fit(X_train, y_train)
predicted = classifier.predict(X_test)

# get the accuracy
print accuracy_score(y_test, predicted)

Also, sklearn has several other metrics besides accuracy. See them here: sklearn.metrics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!