Keras GridSearchCV使用精度以外的指标

时间:2018-02-04 21:41:04

标签: machine-learning scikit-learn keras grid-search multilabel-classification

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_)

1 个答案:

答案 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