【问题标题】:Return the index of selected test set Python返回所选测试集 Python 的索引
【发布时间】:2020-08-19 07:44:14
【问题描述】:

我正在尝试获取测试数据选择的数据的索引。首先我对我的数据使用 train-test-split

A = [[1,2],[3,4],[6,2],[3,4]]
y = [1,0,0,1]

from sklearn.model_selection import train_test_split
A_train, A_test,y_train,y_test = train_test_split(A, y ,test_size=0.3,random_state=1)

A_test
>> [[3, 4], [6, 2]]

但是,如何获取 A_test 在 A 中的索引?例如,在这种情况下,它应该返回 3、4。非常感谢!

【问题讨论】:

    标签: python scikit-learn train-test-split


    【解决方案1】:

    只需在Ay 之上使用range(len(A))

    from sklearn.model_selection import train_test_split
    A_train, A_test, y_train, y_test, index_train, index_test = \
        train_test_split(A, y, range(len(A)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-11
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多