|
34 | 34 | import scipy.sparse as sp
|
35 | 35 |
|
36 | 36 | from .base import BaseEstimator, TransformerMixin
|
37 |
| -from .base import _check_feature_names_in |
| 37 | +from .base import _ClassNamePrefixFeaturesOutMixin |
38 | 38 |
|
39 | 39 | from .utils import check_random_state
|
40 | 40 | from .utils.extmath import safe_sparse_dot
|
@@ -291,7 +291,9 @@ def _sparse_random_matrix(n_components, n_features, density="auto", random_state
|
291 | 291 | return np.sqrt(1 / density) / np.sqrt(n_components) * components
|
292 | 292 |
|
293 | 293 |
|
294 |
| -class BaseRandomProjection(TransformerMixin, BaseEstimator, metaclass=ABCMeta): |
| 294 | +class BaseRandomProjection( |
| 295 | + TransformerMixin, BaseEstimator, _ClassNamePrefixFeaturesOutMixin, metaclass=ABCMeta |
| 296 | +): |
295 | 297 | """Base class for random projections.
|
296 | 298 |
|
297 | 299 | Warning: This class should not be used directly.
|
@@ -421,25 +423,10 @@ def transform(self, X):
|
421 | 423 | X_new = safe_sparse_dot(X, self.components_.T, dense_output=self.dense_output)
|
422 | 424 | return X_new
|
423 | 425 |
|
424 |
| - def get_feature_names_out(self, input_features=None): |
425 |
| - """Get output feature names for transformation. |
426 |
| -
|
427 |
| - Parameters |
428 |
| - ---------- |
429 |
| - input_features : array-like of str or None, default=None |
430 |
| - Not used, present here for API consistency by convention. |
431 |
| -
|
432 |
| - Returns |
433 |
| - ------- |
434 |
| - feature_names_out : ndarray of str objects |
435 |
| - Transformed feature names. |
436 |
| - """ |
437 |
| - _check_feature_names_in(self, input_features) |
438 |
| - class_name = self.__class__.__name__.lower() |
439 |
| - return np.asarray( |
440 |
| - [f"{class_name}{i}" for i in range(self.n_components)], |
441 |
| - dtype=object, |
442 |
| - ) |
| 426 | + @property |
| 427 | + def _n_features_out(self): |
| 428 | + """Number of transformed output features.""" |
| 429 | + return self.n_components |
443 | 430 |
|
444 | 431 |
|
445 | 432 | class GaussianRandomProjection(BaseRandomProjection):
|
|
0 commit comments