我正在研究CNN模型,我正在尝试使用以下代码在我的模型上进行GridSearchCV:
from tensorflow.keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import GridSearchCV, KFold
model = KerasClassifier(build_fn=create_model, batch_size=250, verbose=0)
param_grid = {'dropout_rate':[0,0.05],
'lrate':[0.00004, 0.00006],
'epochs':[30],
'batch_size':[75, 50]}
grid = GridSearchCV(estimator=model, param_grid=param_grid, cv=5)
model = grid.fit(train_Images, y_train, validation_data=(test_Images, y_test))
# summarize results
print("Best: %f using %s" % (model.best_score_, model.best_params_))
这是我得到的结果: 最佳:0.897916,使用{'batch_size':75,'dropout_rate':0,'epochs':30,'lrate':4e-05}
但是,如果我使用相同的数据和相同的参数,则我的准确度约为0.8。
model = create_model(dropout_rate = 0, lrate=0.00004)
batch_size = 75
epochs = 30
# train model
history = model.fit(train_Images, y_train, batch_size=batch_size,
epochs=epochs, validation_data=(test_Images, y_test))
这是什么问题?