gpt4 book ai didi

python - sklearn StratfiedShuffleSplit

转载 作者:太空宇宙 更新时间:2023-11-03 21:35:21 25 4
gpt4 key购买 nike

有人可以帮我理解 StratifiedShuffleSplit 的作用吗?我是这个图书馆的新手。我了解分层采样背后的原理,但是就代码而言,StratifiedShuffleSplit 函数到底返回什么?

我正在阅读的书有以下代码,但是我不太明白。该函数实际上是否在数据帧上添加了一个索引来区分测试与训练,这就是为什么他们使用 .loc 的原因?收入猫列到底是按什么来划分的?谢谢!

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]

最佳答案

Does the function actually add an index on the dataframe that distinguishes between test vs training, which is why they are then using .loc?

它不是添加索引,索引已经存在,但是该函数基本上返回索引的拆分,以便您可以使用 .loc 调用它

And what exactly is it splitting the income_cat column by?

分层随机分割的想法是,对于每次分割,它将保留 y 中标签的原始分布。

关于python - sklearn StratfiedShuffleSplit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53273441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com