【问题标题】:scikit learn GridSearchCV always returns the first parameters as bestscikit learn GridSearchCV 总是返回最好的第一个参数
【发布时间】:2015-04-06 00:03:05
【问题描述】:

我将 GridSearchCV 的参数设置为:

parameters = {'kernel':['rbf'], 'C':[1, 5, 0.5], 'gamma':[1, 5, 0.5]}
grid = GridSearchCV(SVC(), parameters)
grid.fit(dataset, targets)

然后grid.best_params_grid.best_estimator_ 总是返回列表中的第一个参数是最好的(即 1 和 1)。如果我更改参数的顺序并将 5 放在 'C' 的列表顶部,那么最佳参数是 'C'=5 和 'gamma'=1。

我做错了什么?

【问题讨论】:

  • 参数之间的分数可能没有变化。您是否查看过grid_scores_ 属性或设置了详细程度参数?这尤其适用于小型数据集。此外,您的参数非常接近。
  • 你有没有找到任何解决方案,因为我正在努力解决同样的问题。

标签: scikit-learn


【解决方案1】:

你必须将评分参数更改为 (roc_auc),她就是一个例子:

    grid = GridSearchCV(model, param_grid = p, scoring='roc_auc')
    grid.fit(self.train_data, self.train_labels)
    print('\nThe best hyper-parameter for -- {} is {}, the corresponding mean accuracy through 10 Fold test is {} \n'\
        .format(name, grid.best_params_, grid.best_score_))
    model = grid.best_estimator_
    train_pred = model.predict(self.train_data)
    print('{} train accuracy = {}\n'.format(name,(train_pred == self.train_labels).mean()))

【讨论】:

  • 通过使用评分得到此错误raise ValueError("{0} format is not supported".format(y_type)) ValueError: multiclass format is not supported
猜你喜欢
  • 2021-12-18
  • 2020-04-25
  • 1970-01-01
  • 2017-11-23
  • 2019-07-25
  • 2013-10-01
  • 2014-07-28
  • 2018-05-14
  • 2014-02-21
相关资源
最近更新 更多