簡體   English   中英

如何將數據集分成三個相等的部分?

[英]How to partition a dataset into three equal parts?

我正在嘗試使用 scikit-learn 將我的數據集分成三個相等的部分。 但是當我使用 StratifiedKFold(在 sklearn 上)來執行此操作時,它只顯示了我為分區數據集所做的命令,而不是結果:

from sklearn.model_selection import StratifiedKFold
partition = StratifiedKFold(n_splits = 3, shuffle = True, random_state = None)
print(partition)

我還是 Python 庫的新手,所以我不知道該怎么做。

您的代碼的第二行創建了一個 StratifiedKFold object,它並沒有真正對您的數據進行分區。 您應該使用此 object 來拆分數據(請參見下面的示例)

partition = StratifiedKFold(n_splits = 3, shuffle = True, random_state = 1)

for train_index, test_index in partition.split(x, y):
    x_train_f, x_test_f = x[train_index], x[test_index]
    y_train_f, y_test_f = y[train_index], y[test_index]

您將數據分成 3 部分的答案已在此處得到解答

X_train, X_test, X_validate  = np.split(X, [int(.7*len(X)), int(.8*len(X))])
y_train, y_test, y_validate  = np.split(y, [int(.7*len(y)), int(.8*len(y))])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM