[英]How can I find X_train indexes in the main dataset?
我們可以通過 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 = 數組([ 2, 4, 5, 6])
如何在數據中找到子集的索引?
作為記錄sklearn.model_selection.train_test_split
,它是一個快速應用sklearn.model_selection.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]])
所以你可以使用ShuffleSplit
制作的train_ind
和/或test_ind
,它和使用train_test_split
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.