sklearn kfold在python中返回错误的索引

sklearn kfold在python中返回错误的索引,第1张

概述我在 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]
总结

以上是内存溢出为你收集整理的sklearn kfold在python中返回错误的索引全部内容,希望文章能够帮你解决sklearn kfold在python中返回错误的索引所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1206980.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存