ClassNamePrefixFeaturesOutMixin#

class sklearn.base.ClassNamePrefixFeaturesOutMixin[source]#

Mixin 类,用于通过添加前缀生成名称的转换器。

当转换器需要生成自己的输出特征名称时,此 mixin 非常有用,例如 PCA。例如,如果 PCA 输出 3 个特征,则生成的输出特征名称为:["pca0", "pca1", "pca2"]

此 mixin 假设在拟合转换器时定义了 _n_features_out 属性。 _n_features_out 是转换器将在 transformfit_transform 中返回的输出特征数量。

示例

>>> import numpy as np
>>> from sklearn.base import ClassNamePrefixFeaturesOutMixin, BaseEstimator
>>> class MyEstimator(ClassNamePrefixFeaturesOutMixin, BaseEstimator):
...     def fit(self, X, y=None):
...         self._n_features_out = X.shape[1]
...         return self
>>> X = np.array([[1, 2], [3, 4]])
>>> MyEstimator().fit(X).get_feature_names_out()
array(['myestimator0', 'myestimator1'], dtype=object)
get_feature_names_out(input_features=None)[source]#

获取转换的输出特征名称。

The feature names out will prefixed by the lowercased class name. For example, if the transformer outputs 3 features, then the feature names out are: ["class_name0", "class_name1", "class_name2"].

参数:
input_featuresarray-like of str or None, default=None

Only used to validate feature names with the names seen in fit.

返回:
feature_names_outstr 对象的 ndarray

转换后的特征名称。