|
16 | 16 | from scipy import optimize
|
17 | 17 | from scipy.special import boxcox
|
18 | 18 |
|
19 |
| -from ..base import BaseEstimator, TransformerMixin, _OneToOneFeatureMixin |
| 19 | +from ..base import ( |
| 20 | + BaseEstimator, |
| 21 | + TransformerMixin, |
| 22 | + _OneToOneFeatureMixin, |
| 23 | + _ClassNamePrefixFeaturesOutMixin, |
| 24 | +) |
20 | 25 | from ..utils import check_array
|
21 | 26 | from ..utils.deprecation import deprecated
|
22 | 27 | from ..utils.extmath import _incremental_mean_and_var, row_norms
|
|
35 | 40 | check_random_state,
|
36 | 41 | _check_sample_weight,
|
37 | 42 | FLOAT_DTYPES,
|
38 |
| - _check_feature_names_in, |
39 | 43 | )
|
40 | 44 |
|
41 | 45 | from ._encoders import OneHotEncoder
|
@@ -2120,7 +2124,7 @@ def _more_tags(self):
|
2120 | 2124 | return {"stateless": True}
|
2121 | 2125 |
|
2122 | 2126 |
|
2123 |
| -class KernelCenterer(TransformerMixin, BaseEstimator): |
| 2127 | +class KernelCenterer(_ClassNamePrefixFeaturesOutMixin, TransformerMixin, BaseEstimator): |
2124 | 2128 | r"""Center an arbitrary kernel matrix :math:`K`.
|
2125 | 2129 |
|
2126 | 2130 | Let define a kernel :math:`K` such that:
|
@@ -2259,25 +2263,14 @@ def transform(self, K, copy=True):
|
2259 | 2263 |
|
2260 | 2264 | return K
|
2261 | 2265 |
|
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_ |
2281 | 2274 |
|
2282 | 2275 | def _more_tags(self):
|
2283 | 2276 | return {"pairwise": True}
|
|
0 commit comments