You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SGDClassifier: referencing 'predict_proba' method in unfitted object throws error #10938
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.
fromsklearn.linear_modelimportSGDClassifierclassifier=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.
changed the title [-]SGDClassifier: accessing 'predict_proba' function in unfitted object throws error[/-][+]SGDClassifier: referencing 'predict_proba' method in unfitted object throws error[/+]on Apr 8, 2018
Great! Although my issue here was not really about not being able to output probabilities without fitting first, but more about not being able to reference the method itself - for example, it also fails if I try to assign it without calling it:
Activity
[-]SGDClassifier: accessing 'predict_proba' function in unfitted object throws error[/-][+]SGDClassifier: referencing 'predict_proba' method in unfitted object throws error[/+]jnothman commentedon Apr 10, 2018
Hmm... Yes, I would accept not checking if fitted here and rely on the current loss parameter to determine probability support
david-cortes commentedon Apr 10, 2018
Great! Although my issue here was not really about not being able to output probabilities without fitting first, but more about not being able to reference the method itself - for example, it also fails if I try to assign it without calling it:
jnothman commentedon Apr 10, 2018
aniruddhadave commentedon Apr 11, 2018
Hi, I can take this up and remove not fitted check. Seems like a good first issue.
jnothman commentedon Apr 11, 2018
Add test case for issue scikit-learn#10938
Issue scikit-learn#10938: Code Cleanup