for in在python中什么意思,将两个变量放在python中的for-in循环中是什么意思

这篇博客探讨了Python中的`for-in`循环,特别是当它用于迭代返回元组的`StratifiedShuffleSplit`函数时。通过示例解释了如何在循环中同时赋值给两个变量,并与直接赋值和`enumerate`函数的用法进行了对比。
摘要由CSDN通过智能技术生成

from sklearn.model_selection import StratifiedShuffleSplit

split = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state=42)

for train_index, test_index in split.split(housing, housing["income_cat"]):

strat_train_set = housing.loc[train_index]

strat_test_set = housing.loc[test_index]

I printed out the train_index and test_index, they are array of indices.

What does this for loop mean? The train_index and test_index have different number of elements, how does iteration work?

Is this code equivalent to the below?

from sklearn.model_selection import StratifiedShuffleSplit

split = StratifiedShuffleSplit(n_splits=1, test_size=0.2, random_state=42)

train_index, test_index = split.split(housing, housing["income_cat"]):

strat_train_set = housing

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值