8000 SGDClassifier: referencing 'predict_proba' method in unfitted object throws error · Issue #10938 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content
SGDClassifier: referencing 'predict_proba' method in unfitted object throws error #10938
Closed
@david-cortes

Description

@david-cortes

If I initialize an SGDClassifier object and try to access its 'predict_proba' method (not calling it, just referencing it), it throws NotFittedError

E.g.

from sklearn.linear_model import SGDClassifier

classifier = SGDClassifier()
classifier.predict_proba
# no parentheses on function

throws:

NotFittedError                            Traceback (most recent call last)
<ipython-input-6-02b9a01573f0> in <module>()
----> 1 a.predict_proba

~/anaconda3/lib/python3.6/site-packages/sklearn/linear_model/stochastic_gradient.py in predict_proba(self)
    832         http://jmlr.csail.mit.edu/papers/volume2/zhang02c/zhang02c.pdf
    833         """
--> 834         self._check_proba()
    835         return self._predict_proba
    836 

~/anaconda3/lib/python3.6/site-packages/sklearn/linear_model/stochastic_gradient.py in _check_proba(self)
    790 
    791     def _check_proba(self):
--> 792         check_is_fitted(self, "t_")
    793 
    794         if self.loss not in ("log", "modified_huber"):

~/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py in check_is_fitted(estimator, attributes, msg, all_or_any)
    766 
    767     if not all_or_any([hasattr(estimator, attr) for attr in attributes]):
--> 768         raise NotFittedError(msg % {'name': type(estimator).__name__})
    769 
    770 

NotFittedError: This SGDClassifier instance is not fitted yet. Call 'fit' with appropriate arguments before using this method.

However, the method is not being used, just referenced, which shouldn't cause an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0