类名前缀特征输出混合类#
- class sklearn.base.ClassNamePrefixFeaturesOutMixin[source]#
用于生成其自身名称(通过添加前缀)的转换器的混合类。
当转换器需要自己生成特征名称时,此mixin很有用,例如
PCA
。例如,如果PCA
输出3个特征,则生成的特征名称为:["pca0", "pca1", "pca2"]
。此mixin假设在拟合转换器时定义了
_n_features_out
属性。_n_features_out
是转换器将在transform
或fit_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)