Skip to content

Commit

Permalink
Merge pull request #44 from Richie94/upgrade-scikitlearn-1.3
Browse files Browse the repository at this point in the history
Upgrade to comply with scikitlearn >1.3
  • Loading branch information
lopuhin authored Dec 23, 2024
2 parents a3a420a + def1dfd commit 8eed51a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions eli5/sklearn/permutation_importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numpy as np
from sklearn.model_selection import check_cv
from sklearn.utils.metaestimators import if_delegate_has_method
from sklearn.utils.metaestimators import available_if
from sklearn.utils import check_array, check_random_state
from sklearn.base import (
BaseEstimator,
Expand All @@ -20,6 +20,12 @@
if pandas_available:
import pandas as pd

def _estimator_has(attr):
def check(self):
return hasattr(self.wrapped_estimator_, attr)

return check

CAVEATS_CV_NONE = """
Feature importances are computed on the same data as used for training,
i.e. feature importances don't reflect importance of features for
Expand Down Expand Up @@ -247,23 +253,23 @@ def caveats_(self):

# ============= Exposed methods of a wrapped estimator:

@if_delegate_has_method(delegate='wrapped_estimator_')
@available_if(_estimator_has('score'))
def score(self, X, y=None, *args, **kwargs):
return self.wrapped_estimator_.score(X, y, *args, **kwargs)

@if_delegate_has_method(delegate='wrapped_estimator_')
@available_if(_estimator_has('predict'))
def predict(self, X):
return self.wrapped_estimator_.predict(X)

@if_delegate_has_method(delegate='wrapped_estimator_')
@available_if(_estimator_has('predict_proba'))
def predict_proba(self, X):
return self.wrapped_estimator_.predict_proba(X)

@if_delegate_has_method(delegate='wrapped_estimator_')
@available_if(_estimator_has('predict_log_proba'))
def predict_log_proba(self, X):
return self.wrapped_estimator_.predict_log_proba(X)

@if_delegate_has_method(delegate='wrapped_estimator_')
@available_if(_estimator_has('decision_function'))
def decision_function(self, X):
return self.wrapped_estimator_.decision_function(X)

Expand Down

0 comments on commit 8eed51a

Please sign in to comment.