8000 Make KernelCenterer inherit from _ClassNamePrefixFeaturesOutMixin · scikit-learn/scikit-learn@2cd55e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2cd55e9

Browse files
committed
Make KernelCenterer inherit from _ClassNamePrefixFeaturesOutMixin
1 parent a3147d8 commit 2cd55e9

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

sklearn/preprocessing/_data.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
from scipy import optimize
1717
from scipy.special import boxcox
1818

19-
from ..base import BaseEstimator, TransformerMixin, _OneToOneFeatureMixin
19+
from ..base import (
20+
BaseEstimator,
21+
TransformerMixin,
22+
_OneToOneFeatureMixin,
23+
_ClassNamePrefixFeaturesOutMixin,
24+
)
2025
from ..utils import check_array
2126
from ..utils.deprecation import deprecated
2227
from ..utils.extmath import _incremental_mean_and_var, row_norms
@@ -35,7 +40,6 @@
3540
check_random_state,
3641
_check_sample_weight,
3742
FLOAT_DTYPES,
38-
_check_feature_names_in,
3943
)
4044

4145
from ._encoders import OneHotEncoder
@@ -2120,7 +2124,7 @@ def _more_tags(self):
21202124
return {"stateless": True}
21212125

21222126

2123-
class KernelCenterer(TransformerMixin, BaseEstimator):
2127+
class KernelCenterer(_ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator):
21242128
r"""Center an arbitrary kernel matrix :math:`K`.
21252129
21262130
Let define a kernel :math:`K` such that:
@@ -2259,25 +2263,14 @@ def transform(self, K, copy=True):
22592263

22602264
return K
22612265

2262-
def get_feature_names_out(self, input_features=None):
2263-
"""Get output feature names for transformation.
2264-
2265-
Parameters
2266-
----------
2267-
input_features : array-like of str or None, default=None
2268-
Not used, present here for API consistency by convention.
2269-
2270-
Returns
2271-
-------
2272-
feature_names_out : ndarray of str objects
2273-
Transformed feature names.
2274-
"""
2275-
_check_feature_names_in(self, input_features, generate_names=False)
2276-
class_name = self.__class__.__name__.lower()
2277-
return np.asarray(
2278-
[f"{class_name}{i}" for i in range(self.n_features_in_)],
2279-
dtype=object,
2280-
)
2266+
@property
2267+
def _n_features_out(self):
2268+
"""Number of transformed output features."""
2269+
# Used by _ClassNamePrefixFeaturesOutMixin. This model preserves the
2270+
# number of input features but this is not a one-to-one mapping in the
2271+
# usual sense. Hence the choice not to use _OneToOneFeatureMixin to
2272+
# implement get_feature_names_out for this class.
2273+
return self.n_features_in_
22812274

22822275
def _more_tags(self):
22832276
return {"pairwise": True}

0 commit comments

Comments
 (0)
0