Q1:为什么keras gridsearchCV不允许使用" Accuracy"以外的指标。就像我想要使用的: categorical_accuracy 代替准确度。
Q2:这个准确度如何适用于我现在提供的单热编码数据? model.compile(loss =" categorical_crossentropy",optimizer =" adam",metrics = [' accuracy'])
#-----------------------
model = KerasClassifier(build_fn=grid_create_model, verbose=1)
#grid
learn_rate=[0.1,0.001]
batch_size=[50,100]
epochs =[10,20]
param_grid = dict( learn_rate = learn_rate, batch_size =batch_size, epochs =epochs)
grid = GridSearchCV(estimator = model, param_grid = param_grid, n_jobs=1)
earlyStopping = keras.callbacks.EarlyStopping(monitor='accuracy', patience=0, verbose=1, mode='auto')
# y_train = np.reshape(y_train, (-1,np.shape(y_train)[1]))
grid_result = grid.fit(X_train, y_train,callbacks=[earlyStopping])
print ("\n\ngrid score using params: \n", grid_result.best_score_, " ",grid_result.best_params_)
答案 0 :(得分:0)
GridSearchCV
使用您传递给它的估算器类的score
方法。默认score
是准确性,但您可以通过在调用score
时将KerasClassifier
参数作为scoring
参数传递来轻松覆盖此值。
https://keras.io/scikit-learn-api/
或者,您可以将评分指标传递给GridSearchCV
的{{1}}参数:http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html