我有一個包含 4,000 個示例的訓練資料集,我想將其隨機分成 2 個相等的子資料集,每個子??資料集有 2,000 個。正如這里所建議的,我使用了split和drop方法,如下所示:
I1 = train_df.sample(frac=0.5, random_state=opts.seed)
I2 = train_df.drop(index=I1.index)
然而,它似乎無緣無故地下降了更多的指數:
print(len(train_df))
print(len(I1))
print(len(I2))
4000
2000
1010
我將不勝感激任何關于為什么會發生的見解。
uj5u.com熱心網友回復:
對我來說,它只是train_df有多個相同的索引。這應該按預期作業:
train_df = train_df.reset_index(drop=True)
I1 = train_df.sample(frac=0.5, random_state=opts.seed)
I2 = train_df.drop(index=I1.index)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/518243.html
