Skip to content

Commit

Permalink
Improve is_probabilistic_classifier (fix lighting tests)
Browse files Browse the repository at this point in the history
Try to look inside estimators that wrap other estimators:
predict_proba can be a property in wrapped estimator but a method
in wrapper estimator, so the AttributeError will be raised in
runtime. But we don't want to catch it in runtime because it might
be unrelated. This fixes a failure that appeared after
scikit-learn-contrib/lightning#98 merge
(see https://travis-ci.org/TeamHG-Memex/eli5/jobs/172586529)
  • Loading branch information
lopuhin committed Nov 2, 2016
1 parent f9ae971 commit 7c1f67b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion eli5/sklearn/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import numpy as np
from sklearn.base import MetaEstimatorMixin


def is_multiclass_classifier(clf):
Expand All @@ -19,7 +20,11 @@ def is_multitarget_regressor(clf):

def is_probabilistic_classifier(clf):
""" Return True if a classifier can return probabilities """
return hasattr(clf, 'predict_proba')
if not hasattr(clf, 'predict_proba'):
return False
if isinstance(clf, MetaEstimatorMixin) and hasattr(clf, 'estimator'):
return hasattr(clf.estimator, 'predict_proba')
return True


def has_intercept(estimator):
Expand Down

0 comments on commit 7c1f67b

Please sign in to comment.