我正在尝试将 OneVsRestClassifier 与 SVC 一起用于图像的多分类问题 - 我从 CellProfiler 获得了图像的数字特征。我想使用 GridSearchCV 来查找要使用的超参数,但我被卡住了。
有人对此有解决方案/建议吗?
我已经阅读了谷歌,但似乎我无法解决我的问题。
grid = GridSearchCV(pipe, scoring='f1',
param_grid=param_grid, cv=5,
return_train_score=True,
iid=False,
n_jobs=-1
)
grid.fit(X_train, np.ravel(y_train))
return grid
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import make_pipeline
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
from sklearn.multiclass import OneVsRestClassifier
from sklearn.metrics import classification_report
pipe = make_pipeline(StandardScaler(),
OneVsRestClassifier(SVC(probability=True)))
param_grid = {
'estimator__C': [0.001, 0.01, 0.1, 1, 10, 100],
'estimator__kernel': ['linear', 'rbf', 'poly'],
'estimator__degree': [2, 3, 4, 5, 7, 10],
'estimator__gamma': [0.01, 0.02, 0.03, 0.04, 0.05, 1]
}
clf = grid_search_fit(pipe, param_grid)
preds = clf.predict(X_test)
print(classification_report(y_test, preds, target_names = ['empty', 'good', 'blurred']))
ValueError: Invalid parameter estimator for estimator Pipeline(memory=None,
steps=[('standardscaler',
StandardScaler(copy=True, with_mean=True, with_std=True)),
('onevsrestclassifier',
OneVsRestClassifier(estimator=SVC(C=1.0, cache_size=200,
class_weight=None, coef0=0.0,
decision_function_shape='ovr',
degree=3,
gamma='auto_deprecated',
kernel='rbf', max_iter=-1,
probability=True,
random_state=None,
shrinking=True, tol=0.001,
verbose=False),
n_jobs=None))],
verbose=False). Check the list of available parameters with `estimator.get_params().keys()`.