Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prob_classify causing exceptions when working with scikits. #272

Closed
dchaplinsky opened this issue Jun 12, 2012 · 0 comments
Closed

prob_classify causing exceptions when working with scikits. #272

dchaplinsky opened this issue Jun 12, 2012 · 0 comments

Comments

@dchaplinsky
Copy link

For some reason underlying method predict_proba from sklearn package is not implemented for some of classifiers (LinearSVC, SGD with loss="hinge") and for some of them it returns result in kind of unexpected format:

Traceback (most recent call last):
  File "classify.py", line 42, in <module>
    neg_prob = classifier.prob_classify(feats).prob("neg")
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/nltk/classify/api.py", line 65, in prob_classify
    return self.batch_prob_classify([featureset])[0]
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/nltk/classify/scikitlearn.py", line 74, in batch_prob_classify
    return [self._make_probdist(y_proba[i]) for i in xrange(len(y_proba))]
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/nltk/classify/scikitlearn.py", line 135, in _make_probdist
    for i, p in enumerate(y_proba)))
TypeError: 'numpy.float64' object is not iterable

Also, to enable predict_proba for SVC/NuSVC you need to pass probability=True to the constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants