在Keras中创建深度学习模型时,应该使用Nested CV吗?我一直在运行以下代码,这需要很长时间。我没有一个非常大的数据集(5万行),如果很重要,该任务是二进制分类。
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import GridSearchCV
def create_model():
# create model
model = Sequential()
model.add(Dense(12, input_dim=20, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
return model
estimator = KerasClassifier(build_fn=create_model, epochs=100, batch_size=5, verbose=0)
param_grid = dict(epochs=[10,20,30])
gs = GridSearchCV(estimator=estimator, param_grid=param_grid, n_jobs=-1)
results = cross_val_score(gs, X_train, y_train, cv=2)#, n_jobs = -1)
print("Results: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))