在没有 train_test_split 洗牌的情况下对数据进行分层

stratify data without train_test_split shuffle

我正在尝试 binary_classification 股市数据。

既然是时间序列数据,我不想打乱数据。

我会在不打乱数据的情况下对数据进行分层。

sklearn train_test_split 分层仅在设置为 shuffle=True 时有效。

[参见 documentation: If shuffle=False then stratify must be None.]

还有其他选择吗?

注意:我的模型使用了 xgboost 算法。

另请注意:我不想使用 train_test_split 功能。我已经像这样手动完成了。

train_df = df.iloc[0: math.floor(9 * len(df)/10)]
test_df = df.iloc[math.floor(9 * len(df)/10):]

您尝试过使用 StratifiedKFold 吗? 你可以给超参数 shuffe =Flase 它将以折叠数

生成训练和测试数据的索引

这是文档link

https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.StratifiedKFold.html?highlight=stratified#sklearn.model_selection.StratifiedKFold

这可能有帮助