在 SciKit-Learn 中同时使用递归特征消除和网格搜索
Use both Recursive Feature Eliminiation and Grid Search in SciKit-Learn
我有机器学习问题,想优化我的 SVC 估计器和特征选择。
为了优化 SVC 估计器,我主要使用 docs. Now my question is, how can I combine this with recursive feature elimination cross validation (RCEV)?也就是说,对于每个估计器组合,我想执行 RCEV 以确定估计器和特征的最佳组合。
我尝试了 this thread 的解决方案,但它产生了以下错误:
ValueError: Invalid parameter C for estimator RFECV. Check the list of available parameters with `estimator.get_params().keys()`.
我的代码如下所示:
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-4,1e-3],'C': [1,10]},
{'kernel': ['linear'],'C': [1, 10]}]
estimator = SVC(kernel="linear")
selector = RFECV(estimator, step=1, cv=3, scoring=None)
clf = GridSearchCV(selector, tuned_parameters, cv=3)
clf.fit(X_train, y_train)
错误出现在clf = GridSearchCV(selector, tuned_parameters, cv=3)
。
我会使用 Pipeline,但这里你有更充分的响应
Recursive feature elimination and grid search using scikit-learn
我有机器学习问题,想优化我的 SVC 估计器和特征选择。
为了优化 SVC 估计器,我主要使用 docs. Now my question is, how can I combine this with recursive feature elimination cross validation (RCEV)?也就是说,对于每个估计器组合,我想执行 RCEV 以确定估计器和特征的最佳组合。
我尝试了 this thread 的解决方案,但它产生了以下错误:
ValueError: Invalid parameter C for estimator RFECV. Check the list of available parameters with `estimator.get_params().keys()`.
我的代码如下所示:
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-4,1e-3],'C': [1,10]},
{'kernel': ['linear'],'C': [1, 10]}]
estimator = SVC(kernel="linear")
selector = RFECV(estimator, step=1, cv=3, scoring=None)
clf = GridSearchCV(selector, tuned_parameters, cv=3)
clf.fit(X_train, y_train)
错误出现在clf = GridSearchCV(selector, tuned_parameters, cv=3)
。
我会使用 Pipeline,但这里你有更充分的响应
Recursive feature elimination and grid search using scikit-learn