Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for Nans in input of Permutation Importance #381

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eli5/sklearn/permutation_importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_sklearn_permutation_importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
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)