Skip to content

ENH Raise NotFittedError in get_feature_names_out for VotingClassifier and Voting Regressor #25398

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

Closed
Closed
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
4 changes: 3 additions & 1 deletion doc/whats_new/v1.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Changes impacting all modules
raises a `NotFittedError` if the instance is not fitted. This ensures the error is
consistent in all estimators with the `get_feature_names_out` method.

- :class:`ensemble.VotingClassifier`
- :class:`ensemble.VotingRegressor`
- :class:`kernel_approximation.AdditiveChi2Sampler`
- :class:`preprocessing.Binarizer`
- :class:`preprocessing.MaxAbsScaler`
Expand All @@ -56,7 +58,7 @@ Changes impacting all modules
The `NotFittedError` displays an informative message asking to fit the instance
with the appropriate arguments.

:pr:`25294` by :user:`John Pangas <jpangas>` and :pr:`25291` by
:pr:`25294` by :user:`John Pangas <jpangas>` and :pr:`25291`, :pr:`xxxxx` by
:user:`Rahil Parikh <rprkh>`.

Changelog
Expand Down
2 changes: 2 additions & 0 deletions sklearn/ensemble/_voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def get_feature_names_out(self, input_features=None):
feature_names_out : ndarray of str objects
Transformed feature names.
"""
check_is_fitted(self, "n_features_in_")
if self.voting == "soft" and not self.flatten_transform:
raise ValueError(
"get_feature_names_out is not supported when `voting='soft'` and "
Expand Down Expand Up @@ -647,6 +648,7 @@ def get_feature_names_out(self, input_features=None):
feature_names_out : ndarray of str objects
Transformed feature names.
"""
check_is_fitted(self, "n_features_in_")
_check_feature_names_in(self, input_features, generate_names=False)
class_name = self.__class__.__name__.lower()
return np.asarray(
Expand Down
2 changes: 0 additions & 2 deletions sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,6 @@ def test_transformers_get_feature_names_out(transformer):
"StackingClassifier",
"StackingRegressor",
"VarianceThreshold",
"VotingClassifier",
"VotingRegressor",
]


Expand Down