AttributeError:'LinearSVC' object has no attribute 'predict_proba'
·
Answer a question
I am trying to use LinearSVC classifier
Update: Added imports
import nltk
from nltk.tokenize import word_tokenize
from nltk.classify.scikitlearn import SklearnClassifier
from sklearn.svm import LinearSVC, SVC
LinearSVC_classifier = SklearnClassifier(LinearSVC())
LinearSVC_classifier.train(featuresets)
But when I am trying to classify it with probabilities
LinearSVC_classifier.prob_classify(feats)
AttributeError occurs:
AttributeError:'LinearSVC' object has no attribute 'predict_proba'
I checked sklearn documentation, it tells that this function exist.
How to fix that?
Answers
According to sklearn documentation , the method 'predict_proba' is not defined for 'LinearSVC'
Workaround:
LinearSVC_classifier = SklearnClassifier(SVC(kernel='linear',probability=True))
Use SVC with linear kernel, with probability argument set to True. Just as explained in here .
更多推荐
所有评论(0)