开发者社区 问答 正文

如何在主数据集中找到X_train索引?

在Python中,我们可以通过Sklearn函数将数据集分割为X_train、y_train。

X_train, X_test, y_train, y_test = train_test_split(X, y, shuffle=True, test_size=0.3)

我的问题是:如何在数据集中找到X_train或y_train索引? 假设我们通过

prediction = model.predict(X_test)

另外,我们如何找到预测的指标? 我这样问是因为我想看到每一行的值当我得到不准确的结果。 换句话说,数据是主数据集,子集是数据的子集 数据=数组([0,1,2,3,4,5,6,7,8,9]) subest = array([2,4,5,6]) 如何在数据中找到子集的索引? 问题来源StackOverflow 地址:/questions/59384457/how-can-i-find-x-train-indexes-in-the-main-dataset

展开
收起
kun坤 2019-12-26 14:38:51 613 分享 版权
1 条回答
写回答
取消 提交回答
  • 如sklearn.model_selection中所述。train_test_split,是sklearn.model_select . shufflesplit的快速应用:

    from sklearn.model_selection import ShuffleSplit, train_test_split
    
    x_train, x_test, y_train, y_test = train_test_split(X, y, random_state=1, test_size=1)
    x_train
    array([[2, 3],
           [8, 9],
           [0, 1],
           [6, 7]])
    

    这是由ShuffleSplit的拆分索引集产生的收益:

    train_ind, test_ind = next(ShuffleSplit(random_state=1).split(X, y))
    X[train_ind]
    array([[2, 3],
           [8, 9],
           [0, 1],
           [6, 7]])
    

    你可以使用train_ind和/或由ShuffleSplit生成的test_ind,它和使用train_test_split是一样的

    2019-12-26 14:38:57
    赞同 展开评论
问答分类:
问答地址: