我正在为具有时间序列拆分的SVR设计执行grid-search。我的问题是网格搜索大约需要30+分钟,这太长了。我有一个由17,800位数据组成的大型数据集,但是,这个持续时间太长了。有什么办法可以缩短这段时间吗?我的代码是:
from sklearn.svm import SVR
from sklearn.model_selection import TimeSeriesSplit
from sklearn import svm
from sklearn.preprocessing import MinMaxScaler
from sklearn import preprocessing as pre
X_feature = X_feature.reshape(-1, 1)
y_label = y_label.reshape(-1,1)
param = [{'kernel': ['rbf'], 'gamma': [1e-2, 1e-3, 1e-4, 1e-5],
'C': [1, 10, 100, 1000]},
{'kernel': ['poly'], 'C': [1, 10, 100, 1000], 'degree': [1, 2, 3, 4]}]
reg = SVR(C=1)
timeseries_split = TimeSeriesSplit(n_splits=3)
clf = GridSearchCV(reg, param, cv=timeseries_split, scoring='neg_mean_squared_error')
X= pre.MinMaxScaler(feature_range=(0,1)).fit(X_feature)
scaled_X = X.transform(X_feature)
y = pre.MinMaxScaler(feature_range=(0,1)).fit(y_label)
scaled_y = y.transform(y_label)
clf.fit(scaled_X,scaled_y )我对scaled y的数据是:
[0.11321139]
[0.07218848]
...
[0.64844211]
[0.4926122 ]
[0.4030334 ]]我的缩放X的数据是:
[[0.2681013 ]
[0.03454225]
[0.02062136]
...
[0.92857565]
[0.64930691]
[0.20325924]]发布于 2018-07-05 03:59:00
使用GridSearchCV(..., n_jobs=-1)以并行使用所有可用的CPU核心。
或者,您可以使用RandomizedSearchCV
发布于 2018-07-05 05:47:18
根据数据大小和分类器的不同,这可能需要很长时间。或者,您可以尝试将进程分解为更小的部分,每次只使用一次内核,
param_rbf = {'kernel': ['rbf'], 'gamma': [1e-2, 1e-3, 1e-4, 1e-5],
'C': [1, 10, 100, 1000]}然后像这样使用它
clf = GridSearchCV(reg, param_rbf, cv=timeseries_split, scoring='neg_mean_squared_error')类似地,通过不同参数字典分别对不同的核函数进行预测
params_poly = {'kernel': ['poly'], 'C': [1, 10, 100, 1000], 'degree': [1, 2, 3, 4]}我知道这不是一个确切的解决方案,但只是一些建议,如果可能的话,可以帮助你减少时间。
另外,将verbose选项设置为True。这将帮助您显示分类器的进度。
此外,设置n_jobs=-1可能不一定会降低速度。See this answer以供参考。
https://stackoverflow.com/questions/51180033
复制相似问题