sklearn StratfiedShuffle拆分
sklearn StratfiedShuffleSplit
有人可以帮助我了解 StratifiedShuffleSplit 的作用吗?我是这个图书馆的新手。我了解分层抽样背后的原理,但是就代码而言,StratifiedShuffleSplit 函数 return 到底是做什么的?
我正在阅读的书中有以下代码,但我不太理解。该函数实际上是否在数据帧上添加了一个索引来区分测试与训练,这就是他们随后使用 .loc 的原因? income_cat 列的拆分依据究竟是什么?谢谢!
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?
它没有添加索引,索引已经存在,但是是的,该函数基本上 returns 拆分索引,以便您可以使用 .loc
调用它
And what exactly is it splitting the income_cat column by?
Stratified Shuffle Split 的想法是,对于每次拆分,它将保持标签在 y 中的原始分布。
有人可以帮助我了解 StratifiedShuffleSplit 的作用吗?我是这个图书馆的新手。我了解分层抽样背后的原理,但是就代码而言,StratifiedShuffleSplit 函数 return 到底是做什么的?
我正在阅读的书中有以下代码,但我不太理解。该函数实际上是否在数据帧上添加了一个索引来区分测试与训练,这就是他们随后使用 .loc 的原因? income_cat 列的拆分依据究竟是什么?谢谢!
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?
它没有添加索引,索引已经存在,但是是的,该函数基本上 returns 拆分索引,以便您可以使用 .loc
And what exactly is it splitting the income_cat column by?
Stratified Shuffle Split 的想法是,对于每次拆分,它将保持标签在 y 中的原始分布。