Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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='allow-nan')

if self.cv not in (None, "prefit"):
si = self._cv_scores_importances(X, y, groups=groups, **fit_params)
Expand Down
14 changes: 13 additions & 1 deletion tests/test_sklearn_permutation_importance.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,16 @@ 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 = X.copy()
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)