【问题标题】:Is there a way to do a stratified train/test split without shuffling the data?有没有办法在不打乱数据的情况下进行分层训练/测试拆分?
【发布时间】:2020-06-09 12:05:52
【问题描述】:

我正在使用对时间敏感的数据,并希望保持数据的顺序,但由于我有多个标签,所以对数据进行分层。我还没有找到任何允许这样做的库。

【问题讨论】:

    标签: machine-learning scikit-learn split data-science train-test-split


    【解决方案1】:

    请参考train_test_split documentation

    你可以这样做:

    x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=0, 
                                                        stratify=y)
    

    stratify = y 将使用与输入数据集相同比例的类标签进行分层拆分。

    【讨论】:

      【解决方案2】:

      您好 Juanro,您能否提供一个示例,因为这可能有助于更好地理解问题 谢谢:

      【讨论】:

        猜你喜欢
        • 2021-07-26
        • 2022-06-25
        • 2018-04-22
        • 2015-09-15
        • 2019-10-14
        • 2016-02-27
        • 1970-01-01
        • 2015-06-08
        • 1970-01-01
        相关资源
        最近更新 更多