Keras LSTM输入形状用于网格搜索

时间:2018-11-06 14:06:13

标签: python tensorflow keras lstm grid-search

我建立了LSTM网络,现在我想用Keras进行网格搜索。我在try... except的文档中看到,输入形状必须是二维的。

由于我的LSTM网络,我具有3维输入。我像这样重塑张量:

GridSearchCV

当我进行网格搜索时,我还想改变输入的时间步长(look_back)。如何将其适合我的网格搜索?

更新:

更新scikit-learn的版本后,我的3D输入不再是问题。但是我仍然不知道如何更改nb_samples_train = x_train.shape[0] - look_back num=nb_samples_train x_train_reshaped = np.zeros((nb_samples_train, look_back, dim_x)) y_train_reshaped = np.zeros((nb_samples_train,dim_y)) for i in range(nb_samples_train): y_position = i + look_back x_train_reshaped[i] = x_train[i:y_position] y_train_reshaped[i] = y_train[y_position] nb_samples_test = x_test.shape[0] - look_back x_test_reshaped = np.zeros((nb_samples_test, look_back, dim_x)) y_test_reshaped = np.zeros((nb_samples_test, dim_y)) for i in range(nb_samples_test): y_position = i + look_back x_test_reshaped[i] = x_test[i:y_position] y_test_reshaped[i] = y_test[y_position] x_train_r=x_train_reshaped x_test_r=x_test_reshaped y_train_r=y_train_reshaped y_test_r=y_test_reshaped

0 个答案:

没有答案