輸入字典
new_dict1 = {'ABW':{'ABR':1,'BPR':1,'CBR':1,'DBR':0},'BCW':{'ABR':0,'BPR':0,'CBR':1,'DBR':0},
'CBW':{'ABR':1,'BPR':1,'CBR':0,'DBR':0},'MCW':{'ABR':1,'BPR':1,'CBR':0,'DBR':1},
'DBW':{'ABR':0,'BPR':0,'CBR':1,'DBR':0}}
有沒有辦法對嵌套字典的資料應用 2Fold 交叉驗證?但是,下面提到的這個鏈接“https://stackoverflow.com/questions/45115964/separate-pandas-dataframe-using-sklearns-kfold”將資料拆分為訓練、測驗。我想將資料拆分為訓練、測驗和驗證?
uj5u.com熱心網友回復:
你可以使用這樣的東西:
from sklearn.model_selection import KFold
df = pd.DataFrame(new_dict1)
kf = KFold(n_splits = 2, shuffle = True, random_state = 0)
inds = kf.split(df)
for train_val_index, test_index in inds:
kf = KFold(n_splits = 2, shuffle = True, random_state = 0)
inds2 = kf.split(train_val_index)
for train_index, val_index in inds2:
print(train_index, val_index, test_index)
輸出:
[0] [1] [2 3]
[1] [0] [2 3]
[0] [1] [0 1]
[1] [0] [0 1]
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/471969.html
