有没有办法将熊猫数据帧分割成多个相互排斥的样本(长度不同),并按变量分层
我目前的方法是对每个样本使用sci kit learn中的train_test_split多次,但感觉效率非常低
cell_to_split, cell_1 = train_test_split(data, test_size=50, stratify=strat_variable)
cell_to_split, cell_2 = train_test_split(cell_to_split, test_size=60, stratify=strat_variable)
cell_to_split, cell_3 = train_test_split(cell_to_split, test_size=40, stratify=strat_variable)
# strat_variable here is a string variable in data or cell_to_split i'm using for random stratified sampling
这使我可以从数据集中获得3个样本,每个样本都具有指定的大小(行数),平衡了strat_变量的代表性,但效率不太高,理想情况下,我希望样本数(此处设置为3)是动态的
目前没有回答
相关问题 更多 >
编程相关推荐