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?
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 .
You can use _predict_proba_lr()
instead predict_proba
. Something like this:
from sklearn import svm
clf=svm.LinearSVC()
clf.fit(X_train,Y_train)
res= clf._predict_proba_lr(X_test,Y_test)
res would be a 2d array of probabilities of each classes against samples.
Given your question, there is no mentioning about some outside-wrapper like NLTK (except for the tag), so it's hard to grasp what you really need!
Vivek Kumar's comment applies. LinearSVC has no support for probabilities, while SVC does.
Now some additional remarks:
It seems someone observed this problem before.
This can happen if there is a mistmatch between scikit-learn module versions between trained model and the predicted model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With