0
votes

Q1: Why keras gridsearchCV does not allow using metrics other than "Accuracy". Like I want to use: categorical_accuracy in place of accuracy.

Q2: How does this accuracy work for one-hot-encoded data as I am giving now? 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

1 Answers

0
votes

GridSearchCV uses the score method of the estimator class you pass to it. The default score is accuracy, but you can easily override this by passing in a different metric as the score argument when you call KerasClassifier.

https://keras.io/scikit-learn-api/

Alternatively, you can pass the scoring metric to the scoring argument of GridSearchCV: http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html