本文介绍了python中的KFold到底做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在看本教程:

我进入第9部分,进行了预测。在其中,有一个数据数据称为泰坦尼克号,然后使用以下方法将其分成折叠:

I got to part 9, making predictions. In there there is some data in a dataframe called titanic, which is then divided up in folds using:

# Generate cross validation folds for the titanic dataset.  It return the row indices corresponding to train and test.
# We set random_state to ensure we get the same splits every time we run this.
kf = KFold(titanic.shape[0], n_folds=3, random_state=1)



I am not sure what is it exactly doing and what kind of object kf is. I tried reading the documentation but it did not help much. Also, there are three folds (n_folds=3), why is it later only accessing train and test (and how do I know they are called train and test) in this line?

for train, test in kf:


推荐答案

KFold将提供训练/测试索引,以在训练和测试集中拆分数据。它将数据集分成连续的 k 折叠(默认不改组),然后每个折叠使用一次验证集,而 k-1 剩下的褶皱形成训练集(

KFold object was moved to the sklearn.model_selection module in version 0.20. To import KFold in sklearn 0.20+ use from sklearn.model_selection import KFold. KFold current documentation source

这篇关于python中的KFold到底做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 06:23