sklearn kfold在python中返回错误的索引
发布时间:2020-12-16 23:18:36 所属栏目:Python 来源:网络整理
导读:我在 python上的sklearn包中使用kfold函数在df(数据框)上使用不连续的行索引. 这是代码: kFold = KFold(n_splits=10,shuffle=True,random_state=None)for train_index,test_index in kFold.split(dfNARemove):... 我得到了一些在我的df中不存在的train_inde
我在
python上的sklearn包中使用kfold函数在df(数据框)上使用不连续的行索引.
这是代码: kFold = KFold(n_splits=10,shuffle=True,random_state=None) for train_index,test_index in kFold.split(dfNARemove):... 我得到了一些在我的df中不存在的train_index或test_index. 我能做什么? 解决方法
kFold迭代器为您提供DataFrame的训练和验证对象的位置索引,而不是它们的非连续索引.您可以使用.iloc pandas方法访问您的火车和验证对象:
kFold = KFold(n_splits=10,test_index in kFold.split(dfNARemove): train_data = dfNARemove.iloc[train_index] test_data = dfNARemove.iloc[test_index] 如果您想知道每个折叠上用于train_index和test_index的非连续索引,您可以执行以下操作: non_continuous_train_index = dfNARemove.index[train_index] non_continuous_test_index = dfNARemove.index[test_index] (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读