我正在尝试使用
SVC
作为分类器,使用GridSearchCV
执行带交叉验证的递归特征消除(RFECV)。我的代码如下。X = df[my_features]
y = df['gold_standard']
x_train, x_test, y_train, y_test = train_test_split(X, y, random_state=0)
k_fold = StratifiedKFold(n_splits=10, shuffle=True, random_state=0)
clf = SVC(class_weight="balanced")
rfecv = RFECV(estimator=clf, step=1, cv=k_fold, scoring='roc_auc')
param_grid = {'estimator__C': [0.001, 0.01, 0.1, 0.25, 0.5, 0.75, 1.0, 10.0, 100.0, 1000.0],
'estimator__gamma': [0.001, 0.01, 0.1, 1.0, 2.0, 3.0, 10.0, 100.0, 1000.0],
'estimator__kernel':('rbf', 'sigmoid', 'poly')
}
CV_rfc = GridSearchCV(estimator=rfecv, param_grid=param_grid, cv= k_fold, scoring = 'roc_auc', verbose=10)
CV_rfc.fit(x_train, y_train)
然而,我遇到了一个错误: RuntimeError: 分类器没有公开 "coef_" 或 "feature_importances_" 属性
是否有解决这个错误的方法?如果没有,我可以使用哪些其他特征选择
技术与SVC
一起使用?
如有需要,我很乐意提供更多细节。
从版本0.17开始更改:弃用decision_function_shape ='ovo'和None。
- BCJuanSVC
不支持coef_
。你有什么建议来解决这个问题吗?或者有没有其他支持 SVC 的特征选择技术的推荐? - EmJcoef_
,而是coef0
。 - BCJuan