【发布时间】:2019-09-03 02:01:43
【问题描述】:
我正在尝试使用GridSearchCV 以SVC 作为分类器执行递归特征消除和交叉验证 (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: The classifier does not expose "coef_" or "feature_importances_" attributes
有没有办法解决这个错误?如果不是,我可以与SVC 一起使用的其他feature selection 技术是什么?
如果需要,我很乐意提供更多详细信息。
【问题讨论】:
-
您好,来自文档:
Changed in version 0.17: Deprecated decision_function_shape=’ovo’ and None. -
@BCJuan 我认为问题在于
SVC不支持coef_。你有什么建议可以解决这个问题吗?或任何其他支持 SVC 的特征选择技术的建议? -
它不叫
coef_,而是coef0
标签: python machine-learning scikit-learn svm