scikit-learn/scikit-learn — pull request #2910 by larsmans (2014-02-27 20:06:30+00:00)
Title: [MRG] make hasattr(clf, "predict_proba") work with probabilities disabled

Here's a trick with `property` that @mblondel suggested earlier to make `hasattr(clf, "predict_proba")` work with `SVC(probability=False)` and `SGDClassifier(loss="hinge")`: models that define the method, but where it doesn't actually work.

This is a bit of a hack, so I don't suggest using it in new code (see comment in `SVC`), but it simplifies other code such as bagging and the smoke tests, i.e. it localizes the problem that these exceptional estimators have instead of spreading it across the codebase. There might be more places where the code can be simplified.

The documentation comes out almost right, despite the property:

![predict_proba](https://f.cloud.github.com/assets/335383/2287207/46037cde-9fea-11e3-9128-54e5df18e5ff.png)

(The "returns X" is there in `master` too, I'll change it in a minute.)

Ping @jnothman, @GaelVaroquaux, @agramfort, @ogrisel.