循环遍历分层索引时为 .loc() 赋值



我刚开始学习机器学习,并坚持理解这段代码。我了解分层移位类方法如何生成一组训练和测试索引进行循环。我感到困惑的是strat_train_set如何包含多个值。我尝试运行代码,很明显两个变量都包含集合,但没有增量或添加函数。难道每个运行循环都不会用新记录替换当前记录,从而导致包含日期集的单个记录而不是多个值的strat_train_set和strat_test_set。

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]

此循环在每次迭代时提供整个折叠。train_indextest_index是索引值本身的集合,然后通过.loc()(矢量化操作)将其用作住房DF的多值索引。 因此,strat_train_setstrat_test_set也是集合。

有意义?

最新更新