我正在尝试训练具有1个隐藏层的简单NN进行二进制分类。试图使用GridSeachCV获得最佳参数,但培训不会超出第一个纪元。
没有获得best_parameters = gridSearchCV.best_params_
的任何值,并且
best_accurcy = gridSearchCV.best_score_
在它停止之后。
def build_classifier_grid(optimizer):
classifier_grid = Sequential()
classifier_grid.add(Dense(output_dim = 6, init = 'uniform',activation = 'relu', input_dim = 11))
classifier_grid.add(Dense(output_dim = 6, init = 'uniform',activation = 'relu'))
classifier_grid.add(Dense(output_dim = 1, init = 'uniform',activation = 'sigmoid'))
classifier_grid.compile(optimizer = optimizer, loss = 'binary_crossentropy', metrics = ['accuracy'])
return classifier_grid
classifier_grid = KerasClassifier(build_fn = build_classifier_grid)
parameters = {'batch_size': [25,32],
'nb_epoch' : [100, 500],
'optimizer': ['adam', 'rmsprop']}
gridSearchCV = GridSearchCV(estimator = classifier_grid,
param_grid = parameters,
scoring = 'accuracy',
cv = 10)
gridSearchCV = gridSearchCV.fit(X_train, y_train)
变得像
Epoch 1/1
7200/7200 [==============================] - 5s 676us/step - loss: 0.5647 - acc: 0.7961
Epoch 1/1
7200/7200 [==============================] - 5s 681us/step - loss: 0.5626 - acc: 0.7950
Epoch 1/1
7200/7200 [==============================] - 5s 684us/step - loss: 0.5523 - acc: 0.7956
"
"
Epoch 1/1
7200/7200 [==============================] - 10s 1ms/step - loss: 0.6167 - acc: 0.7929
Epoch 1/1
8000/8000 [==============================] - 11s 1ms/step - loss: 0.5504 - acc: 0.7959
答案 0 :(得分:2)
它完全没有卡住,只是训练每个模型仅一个历时,这是默认值。问题是您使用了参数nb_epoch
,而Keras 2.x中的正确名称是epochs
。