python 中超参数组的并行交叉验证
Paralleled cross validation for groups of hyperparameters in python
我需要针对
的特定组一次 运行 多次交叉验证
SVR hyperparamters: ((C_0,gamma_0),(C_1,gamma_1)...(C_n,gamma_n)) and
thus, seek for a parallelization method to speed it up.
也许可以 运行 GridSearchCV,这样就不会检查每个可能的超参数组合,而是以 'element wise' 方式检查它们。示例:
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4],
'C': [100, 1000]]
clf = GridSearchCV(SVR(), tuned_parameters, cv=5, n_jobs=-1)
clf.fit(X_train, y_train)
因此在这种情况下只会检查两对超参数,即:(1e-3,100) 和 (1e-4,1000) 而不是所有四个组合。
您可以尝试使用字典列表来指定参数。
像这样:
tuned_parameters = [{'kernel': ['rbf'],
'gamma': [1e-3],
'C': [100]},
{'kernel': ['rbf'],
'gamma': [1e-4],
'C': [1000]}]
调用 clf.fit() 现在将在参数列表的两个元素中搜索参数,一次使用一个元素中的所有值。
因此只会使用两种组合:('rbf', 1e-3, 100) 和 ('rbf', 1e-4, 1000)
我需要针对
的特定组一次 运行 多次交叉验证SVR hyperparamters: ((C_0,gamma_0),(C_1,gamma_1)...(C_n,gamma_n)) and thus, seek for a parallelization method to speed it up.
也许可以 运行 GridSearchCV,这样就不会检查每个可能的超参数组合,而是以 'element wise' 方式检查它们。示例:
tuned_parameters = [{'kernel': ['rbf'], 'gamma': [1e-3, 1e-4],
'C': [100, 1000]]
clf = GridSearchCV(SVR(), tuned_parameters, cv=5, n_jobs=-1)
clf.fit(X_train, y_train)
因此在这种情况下只会检查两对超参数,即:(1e-3,100) 和 (1e-4,1000) 而不是所有四个组合。
您可以尝试使用字典列表来指定参数。
像这样:
tuned_parameters = [{'kernel': ['rbf'],
'gamma': [1e-3],
'C': [100]},
{'kernel': ['rbf'],
'gamma': [1e-4],
'C': [1000]}]
调用 clf.fit() 现在将在参数列表的两个元素中搜索参数,一次使用一个元素中的所有值。
因此只会使用两种组合:('rbf', 1e-3, 100) 和 ('rbf', 1e-4, 1000)