Thanks to visit codestin.com
Credit goes to github.com

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
31 changes: 27 additions & 4 deletions sklearn/model_selection/_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ def evaluate_candidates(candidate_params, cv=None, more_results=None):
refit_end_time = time.time()
self.refit_time_ = refit_end_time - refit_start_time

if hasattr(self.best_estimator_, "feature_names_in_"):
self.feature_names_in_ = self.best_estimator_.feature_names_in_

# Store the only scorer not as a dict for single metric evaluation
self.scorer_ = scorers

Expand Down Expand Up @@ -1246,11 +1249,21 @@ class GridSearchCV(BaseSearchCV):
the underlying estimator is a classifier.

n_features_in_ : int
Number of features seen during :term:`fit`. Only defined if the
underlying estimator exposes such an attribute when fit.
Number of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`n_features_in_` when fit.

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`feature_names_in_` when fit.

.. versionadded:: 1.0

Notes
-----
The parameters selected are those that maximize the score of the left out
Expand Down Expand Up @@ -1595,11 +1608,21 @@ class RandomizedSearchCV(BaseSearchCV):
the underlying estimator is a classifier.

n_features_in_ : int
Number of features seen during :term:`fit`. Only defined if the
underlying estimator exposes such an attribute when fit.
Number of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`n_features_in_` when fit.

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`feature_names_in_` when fit.

.. versionadded:: 1.0

Notes
-----
The parameters selected are those that maximize the score of the held-out
Expand Down
28 changes: 24 additions & 4 deletions sklearn/model_selection/_search_successive_halving.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,21 @@ class HalvingGridSearchCV(BaseSuccessiveHalving):
the underlying estimator is a classifier.

n_features_in_ : int
Number of features seen during :term:`fit`. Only defined if the
underlying estimator exposes such an attribute when fit.
Number of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`n_features_in_` when fit.

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`feature_names_in_` when fit.

.. versionadded:: 1.0

See Also
--------
:class:`HalvingRandomSearchCV`:
Expand Down Expand Up @@ -954,11 +964,21 @@ class HalvingRandomSearchCV(BaseSuccessiveHalving):
the underlying estimator is a classifier.

n_features_in_ : int
Number of features seen during :term:`fit`. Only defined if the
underlying estimator exposes such an attribute when fit.
Number of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`n_features_in_` when fit.

.. versionadded:: 0.24

feature_names_in_ : ndarray of shape (`n_features_in_`,)
Names of features seen during :term:`fit`. Only defined if
`best_estimator_` is defined (see the documentation for the `refit`
parameter for more details) and that `best_estimator_` exposes
`feature_names_in_` when fit.

.. versionadded:: 1.0

See Also
--------
:class:`HalvingGridSearchCV`:
Expand Down
7 changes: 5 additions & 2 deletions sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,14 @@ def test_check_n_features_in_after_fitting(estimator):

COLUMN_NAME_MODULES_TO_IGNORE = {
"compose",
"model_selection",
}

_estimators_to_test = list(
chain(_tested_estimators(), [make_pipeline(LogisticRegression(C=1))])
chain(
_tested_estimators(),
[make_pipeline(LogisticRegression(C=1))],
list(_generate_search_cv_instances()),
)
)


Expand Down