From f372520a825bed009cbd1dff5e7fee1cbe39a54b Mon Sep 17 00:00:00 2001 From: uj26kf Date: Fri, 22 May 2020 10:58:52 +0200 Subject: [PATCH 1/2] Allow for Nans in input of Permutation Importance --- eli5/sklearn/permutation_importance.py | 2 +- tests/test_sklearn_permutation_importance.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/eli5/sklearn/permutation_importance.py b/eli5/sklearn/permutation_importance.py index 370be8be..b4be6603 100644 --- a/eli5/sklearn/permutation_importance.py +++ b/eli5/sklearn/permutation_importance.py @@ -196,7 +196,7 @@ def fit(self, X, y, groups=None, **fit_params): self.estimator_ = clone(self.estimator) self.estimator_.fit(X, y, **fit_params) - X = check_array(X) + X = check_array(X, force_all_finite=False) if self.cv not in (None, "prefit"): si = self._cv_scores_importances(X, y, groups=groups, **fit_params) diff --git a/tests/test_sklearn_permutation_importance.py b/tests/test_sklearn_permutation_importance.py index 4ffec3ba..a174cd08 100644 --- a/tests/test_sklearn_permutation_importance.py +++ b/tests/test_sklearn_permutation_importance.py @@ -189,4 +189,14 @@ def test_cv_sample_weight(iris_train): perm = PermutationImportance(model, cv=5, random_state=42).fit(X, y) # passing a vector of weights filled with one should be the same as passing no weights - assert (perm.feature_importances_ == perm_weights.feature_importances_).all() \ No newline at end of file + assert (perm.feature_importances_ == perm_weights.feature_importances_).all() + +def test_allow_nans(iris_train): + xgboost = pytest.importorskip('xgboost') + + X, y, feature_names, target_names = iris_train + X[0, 0] = np.nan + + perm = PermutationImportance(xgboost.XGBClassifier(), cv=5) + # There should be not error thrown during fitting of the model + perm.fit(X, y) From fc22f65585a721ebd475bf868b3fd7083cf67ae8 Mon Sep 17 00:00:00 2001 From: uj26kf Date: Wed, 11 Nov 2020 12:16:53 +0100 Subject: [PATCH 2/2] Update sklearn requirement to 0.20 --- eli5/sklearn/permutation_importance.py | 2 +- requirements.txt | 2 +- setup.py | 2 +- tox.ini | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/eli5/sklearn/permutation_importance.py b/eli5/sklearn/permutation_importance.py index b4be6603..1fd8057a 100644 --- a/eli5/sklearn/permutation_importance.py +++ b/eli5/sklearn/permutation_importance.py @@ -196,7 +196,7 @@ def fit(self, X, y, groups=None, **fit_params): self.estimator_ = clone(self.estimator) self.estimator_.fit(X, y, **fit_params) - X = check_array(X, force_all_finite=False) + X = check_array(X, force_all_finite='allow-nan') if self.cv not in (None, "prefit"): si = self._cv_scores_importances(X, y, groups=groups, **fit_params) diff --git a/requirements.txt b/requirements.txt index ca97e5d2..97eb8df3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ numpy >= 1.9.0 scipy singledispatch >= 3.4.0.3 -scikit-learn >= 0.18 +scikit-learn >= 0.20 attrs > 16.0.0 jinja2 pip >= 8.1 diff --git a/setup.py b/setup.py index ec561515..22b52544 100755 --- a/setup.py +++ b/setup.py @@ -36,7 +36,7 @@ def get_long_description(): 'numpy >= 1.9.0', 'scipy', 'six', - 'scikit-learn >= 0.18', + 'scikit-learn >= 0.20', 'graphviz', 'tabulate>=0.7.7', ], diff --git a/tox.ini b/tox.ini index b0592901..f077963d 100644 --- a/tox.ini +++ b/tox.ini @@ -6,7 +6,7 @@ ; https://github.com/Microsoft/LightGBM/tree/master/python-package#lightgbm-python-package. [tox] -envlist = py27,py34,py35,py35-nodeps,mypy,py35-extra,py27-extra,py36,py36-extra,py36-legacy,py37-nodeps +envlist = py27,py34,py35,py35-nodeps,mypy,py35-extra,py27-extra,py36,py36-extra,py37-nodeps [base] deps=