我正在尝试通过Gridsearch搜索最佳参数来优化模型(使用MLP,LSTM等进行时间序列预测)。我按比例缩放了数据,但是当我运行Gridsearch时,训练期间(两个mse的)损失分值比如果不使用gridsearch时的得分高得多。
没有Gridsearch,我正在做一个简单的火车测试拆分(70/30)。 使用Gridseach,我实现了TimeSeriesSplit。
tscv = TimeSeriesSplit(n_splits=3)
for train_index, test_index in tscv.split(X):
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
def deep_learning_create(units,batch_s):
model=Sequential()
model.add(Dense(units, activation='relu'))
model.add(Dense(1))
optimizer=optimizers.RMSprop()
model.compile(optimizer='adam',loss='mean_squared_error', metrics=['acc'])
return model
model=KerasClassifier(build_fn=deep_learning_create,verbose=1)
#Random Search for optimal hyper-paramters
params_grid_DeepLearning={'layers_num':[1],
'units':[16],
'learning_rate':[0.01],
'batch_size':[32,64,128],
'epochs':[100]}
random_model=GridSearchCV(model,params_grid_DeepLearning,
n_jobs=1,cv=tscv,refit=True, verbose=2)
random_model.fit(X_train, y_train)
没有Gridsearch
史诗1/100 -0秒-损失:0.0325-acc:0.0053 时代2/100 -0s-损失:0.0116-acc:0.0053
使用GridSearch
史诗1/100 101/101 0s 642us / step-损失:3254.1907-acc:0.0099