gpt4 book ai didi

python - 网格搜索需要 30 多分钟,有什么方法可以减少这个时间吗? (Jupyter Azure)

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:06 25 4
gpt4 key购买 nike

我正在对具有时间序列分割的 SVR 设计进行网格搜索。我的问题是网格搜索大约需要 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 )

我的缩放 y 数据是:

 [0.11321139]
[0.07218848]
...
[0.64844211]
[0.4926122 ]
[0.4030334 ]]

我的缩放 X 数据是:

[[0.2681013 ]
[0.03454225]
[0.02062136]
...
[0.92857565]
[0.64930691]
[0.20325924]]

最佳答案

使用 GridSearchCV(..., n_jobs=-1) 以便并行使用所有可用的 CPU 内核。

或者您可以使用 RandomizedSearchCV

关于python - 网格搜索需要 30 多分钟,有什么方法可以减少这个时间吗? (Jupyter Azure),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51180033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com