【发布时间】:2021-03-12 19:14:02
【问题描述】:
通读这本书,我在 scikit-learn 上看到了这一点:
housing["income_cat"] = pd.cut(housing["median_income"], bins=[0.,1.5,3.0,4.5,6.,np.inf], labels=[1,2,3,4,5])
split =StratifiedShuffleSplit(n_splits=1, test_size=0.2, randomstate=42)
for train_index, test_index in split.split(housing, housing["income_cat"])
stat_train_set = housing.loc[train_index]
stat_test_set = housing.loc[test_index]
我知道第一行是向住房数据框添加一列,并附加一个分类收入的分类 1 - 5。
1: 0-<1.5
2: 1.5-<3.0
3: 3.0-<4.5
4: 4.5-<6
5: >6
我知道第二行返回一个要拆分的函数。
我不明白的是函数如何知道两个指数中的哪一个是 20%?第二个索引总是函数应用 test_size 参数的那个吗?
【问题讨论】:
-
您是在问函数如何知道如何将数据分成 80-20%?
-
不,我知道这是来自 StratifiedShuffleSplit() 函数中的 test_size 参数。我不明白循环如何知道将 20% 的采样索引存储在 test_index 而不是 train_index 中。该函数是否总是通过 .split() 函数将 test_size 参数应用于循环中的第二个索引?
-
你自己知道答案我看到了^_^ scikit-learn.org/stable/modules/generated/…阅读这里了解更多信息
-
顺便说一句,这本书不要让你的头脑过于复杂。当你开始习惯机器学习时,你会使用
train_test_split,它更简单、更直观 -
原来是这样吗?它总是将 test_size 参数应用于循环中的第二个索引?还是我应该注意 .split() 函数中的某些内容?
标签: pandas machine-learning scikit-learn