我正在使用递归特征消除(RFE)管道:
from sklearn.feature_selection import RFE
c_GAUSS = GaussianProcessClassifier()
rfe = RFE(estimator=c_GAUSS)但是,我得到一个错误:
ValueError: when `importance_getter=='auto'`, the underlying
estimator GaussianProcessClassifier should have `coef_` or
`feature_importances_` attribute. Either pass a fitted estimator to
feature selector or call fit before calling transform.对于支持向量机,我只是通过在c_SVC = SVC(C = 1)的支持向量机中加入一个系数来解决这个问题。
既然GPC没有系数,这里有没有可能的变通方法?
发布于 2021-08-30 15:21:18
恐怕没有。正如documentation of RFE所说,估计器被期望“为特征分配权重”。兼容的估计器必须通过coef_或feature_importances_属性公开这些权重。看一下RFE的implementation,它非常简单。
我对GaussianProcessClassifier不是很熟悉,但是,这种分类器似乎不会执行任何特征评分。如果您认为在训练后为GPC评分有一种自然的方法,您可以自己扩展GaussianProcessClassifier:
from sklearn.utils.validation import check_X_y
from sklearn.utils.estimator_checks import check_estimator
class WeightedGaussianProcessClassifier(GaussianProcessClassifier):
def fit(self, X, y):
X, y = check_X_y(X, y)
super().fit(X,y)
# Implement here your weight
self.feature_importances_ = ...
return self
check_estimator(WeightedGaussianProcessClassifier)按照here的说明开发您自己的估计器。这样,您就可以使估计器与RFE类兼容。
发布于 2021-08-30 15:03:57
根据RFE documentation,估计器需要关于特征重要性的信息(例如,estimator.coef_,estimator.feature_importances_)。不幸的是,由于GPC中的分类方式,GPC估计器没有提供此属性。
根据Cross Validated上的一个答案,在GP分类中确定特征重要性的一种方法是通过一次连续忽略一个特征来确定分类错误或其他度量标准。这是非常耗时的,并且默认情况下不是由GP完成的。然而,这将需要实现您自己的RFE函数(不是太难)。
https://stackoverflow.com/questions/68985646
复制相似问题