【问题标题】:Specify Index Range on Train Split SciKit-Learn在 Train Split SciKit-Learn 上指定索引范围
【发布时间】:2019-08-08 04:31:58
【问题描述】:

我试图围绕使用数据集中最后 30% 的条目作为测试样本的概念展开思考。没有随机(故意)。这可能吗?

将数据集拆分为训练/测试:

x_train, x_test, y_train, y_test = model_selection.train_test_split(x, y, test_size=0.3,random_state=0)

是否可以以测试拆分仅从数据集末尾选择条目的方式显式控制拆分?

【问题讨论】:

    标签: python-3.x tensorflow scikit-learn


    【解决方案1】:

    如果您替换该行,您将实现您的目标:

    x_train, x_test, y_train, y_test = model_selection.train_test_split(x, y, test_size=0.3,random_state=0)
    

    与:

    idx_train = int((1-.3)* x.shape[0]) # train is (1-.3) of your data
    x_train = x[:idx_train,:]
    x_test = x[idx_train:, :]
    y_train = y[:idx_train]
    y_test = y[idx_train:]
    

    【讨论】:

    • 试过了,它似乎给了我想要的分割。你救了我一整天!
    猜你喜欢
    • 2017-04-23
    • 2014-02-18
    • 2019-07-19
    • 2020-07-14
    • 1970-01-01
    • 2021-08-10
    • 2018-03-19
    相关资源
    最近更新 更多