python - sklearn StratfiedShuffleSplit

标签 python scikit-learn

有人可以帮我理解 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/

相关文章:

python - 如何对列求和并将结果作为一行附加到同一数据框中?

python - 如果所有 python 方法确实都是非数据描述符,我可以覆盖 method.__get__ 吗?

python - Scrapy 在恢复之前做一些事情

python - 通过管道将sample_weight参数与XGBoost结合使用

python - KMeans 如何用于断言数据集有噪声?

python - 作为 pandas 数据框中某个值的列数

python - 以下哪种方法是在 python 中返回的正确方法?

macos - 使用Python 3在scikit-learn上进行大数据序列化

python - SciKit Learn SVR 运行时间很长

Python:当我导入 RandomForestClassifier 时出现 "TypeError: Could not operate with block values"