我是要给cross_val_score()整个数据集,还是只给训练集? [英] Do I give cross_val_score() the entire dataset or just the training-set?

查看:326
本文介绍了我是要给cross_val_score()整个数据集,还是只给训练集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于该类的文档不是很清楚.我不明白我给它带来了什么价值.

cross_val_score(estimator,X,y = None)

这是我的代码:

  clf = LinearSVC(random_state = seed,** params)cvscore = cross_val_score(clf,功能,标签) 

我不确定这是否正确,或者我是否需要提供X_train和y_train而不是功能和标签.

谢谢

解决方案

即使使用cross_val_score,分离测试集和训练集也是一个好主意.其背后的原因是知识泄漏.基本上,这意味着当您同时使用训练集和测试集时,会将信息从测试集泄漏到模型中,从而使模型带有偏见,从而导致错误的预测.

在同一问题上,博客文章详细./p>

参考文献:

As the documentation of the class is not very clear. I don't understand what value I give it.

cross_val_score(estimator, X, y=None)

This is my code:

clf = LinearSVC(random_state=seed, **params)
cvscore = cross_val_score(clf, features, labels)

I am not sure if this is correct or if I need to give X_train and y_train instead of features and labels.

Thanks

解决方案

It is always a good idea to seperate the test set and training set, even while using cross_val_score. The reason behind this is knowledge leaking. It basically means that when you use both training and test sets, you are leaking information from test set into your model, thereby making your model biased, leading to incorrect predictions.

Here is detailed blog post on the same issue.

References:

这篇关于我是要给cross_val_score()整个数据集,还是只给训练集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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