如何在没有交叉验证的情况下运行 GridSearchCV? [英] How to run GridSearchCV without cross-validation?

查看:97
本文介绍了如何在没有交叉验证的情况下运行 GridSearchCV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有简历的情况下运行常规的gridsearch",即我不想交叉验证,但不允许设置 cv=1.

I would like to run a regular 'gridsearch without the CV', i.e. I don't want to cross-validate, but setting cv=1 is not allowed.

我这样做是因为我使用分类器来绘制决策边界并可视化/理解我的数据而不是预测标签,并且不关心泛化错误.我想尽量减少训练误差.

I am doing this because I am using a classifier to draw decision boundaries and visualize/understand my data instead of predicting labels, and do not care about the generalization error. I would like to minimize the training error instead.

我想我真的在问两个问题

I guess I'm really asking two questions

  1. 如何破解GridSearchCV中的cv=1?由以下 ogrisel 回答
  2. 进行网格搜索以最小化训练错误而不是泛化错误是否有意义,如果是这样,我该怎么做?我怀疑这涉及在 GridSearchCV 中为 scoring 参数插入我自己的评分函数?
  1. How to hack cv=1 in GridSearchCV? Answered by ogrisel below
  2. Does it make sense to do a gridsearch to minimize training error instead of generalization error, and if so, how would I do that? I suspect it involves inserting my own scoring function for the scoring parameter in GridSearchCV?

推荐答案

你可以传递一个 ShuffleSplit(test_size=0.20, n_splits=1, random_state=0) 的实例作为 cv 参数.

You can pass an instance of ShuffleSplit(test_size=0.20, n_splits=1, random_state=0) as the cv parameter.

这将对每个参数组合进行单个 CV 拆分(sklearn.model_selection.ShuffleSplit).

That will do a single CV split per parameter combination (sklearn.model_selection.ShuffleSplit).

这篇关于如何在没有交叉验证的情况下运行 GridSearchCV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆