如何为GRU模型设置网格搜索?

时间:2019-06-26 14:08:38

标签: python-3.x keras grid-search

'''嗨!我还没有对NN模型进行网格搜索,它似乎不是像线性回归那样简单的任务。我很困惑。请告诉我我该怎么做,以及如何正确编写它?提前谢谢!'''

from sklearn.pipeline import Pipeline
from sklearn.model_selection import GridSearchCV


activation = ["elu", "exponential", "hard_sigmoid", "linear", "relu", "selu", "sigmoid", "softmax", "softplus", "softsign",
             "tanh"]

optimizer = ["Adadelta", "Adagrad", "Adam", "Adamax", "Ftrl", "Nadam", "ORMSprop", "SGD"]

units = np.geomspace(1, 90, 5)

# prepare grid search (search space)
search_space = [{'activation': activation,
                 'oprimizers': optimizer,
                'units': units}]  # grid 1 for linear regression

pipeline= Pipeline( ("input layer" ,Input(shape=(7,1), dtype='float32')),
                    ("GRU", GRU(units=num_neurons, input_shape=(7,1), return_sequences=False, activation=activation)(input_layer)),
                   ("dropout_layer" ,Dropout(0.2)(gru_layer) ),
                   ("output_layer", Dense(1, activation=activation)(dropout_layer)),
                   ("ts_model", Model(inputs=input_layer, outputs=output_layer)),
                   ("comp", ts_model.compile(loss='mae', optimizer=optimizer,  metrics=['accuracy'])))

# set up grid search
model_grid_cv = GridSearchCV(estimator=pipeline, 
                   param_grid=search_space, 
                   scoring='r2',
                   cv=time_split)

0 个答案:

没有答案