【问题标题】:Keras GridSearchCV using metrics other than AccuracyKeras GridSearchCV 使用精度以外的指标
【发布时间】:2018-07-14 18:15:05
【问题描述】:

Q1:为什么 keras gridsearchCV 不允许使用“准确度”以外的指标。就像我想使用: categorical_accuracy 代替 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_)

【问题讨论】:

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


    【解决方案1】:

    GridSearchCV 使用您传递给它的估计器类的score 方法。默认的score 是准确度,但您可以通过在调用KerasClassifier 时传入不同的指标作为score 参数来轻松覆盖它。

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

    或者,您可以将评分指标传递给GridSearchCVscoring 参数:http://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html

    【讨论】:

      猜你喜欢
      • 2018-11-28
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 2019-05-27
      • 1970-01-01
      相关资源
      最近更新 更多