【发布时间】:2017-05-23 13:57:22
【问题描述】:
我有一个未评级项目的列表,我希望将它们分成 5 折。目前,我已经完成了,因为我只是尝试均匀地分成块,最后一个是所谓的“扩展”块,这给我带来了问题。
当我有nonRatedItems = {1,2,3,4,5,6,7,8} 时,块是:
1
2
3
4
5 6 7 8
我想避免这种情况,所以输出是:
1 6
2 7
3 8
4
5
当前来源:
Collections.shuffle(nonRatedItems);
nonRatedItems = nonRatedItems.subList(0, (int) Math.ceil(nonRatedItems.size() * 0.2));
int tfoldSize = nonRatedItems.size() / 5;
List<List<Integer>> negativeTestFolds = new ArrayList<List<Integer>>();
if (tfoldSize < 1) {
nonRatedItems.stream().map(Lists::newArrayList).collect(Collectors.toCollection(() -> negativeTestFolds));
} else {
for (int i = 0; i < 5; i++) {
int endIndex = i < 4 ? (i + 1) * tfoldSize : nonRatedItems.size();
negativeTestFolds.add(nonRatedItems.subList(i * tfoldSize, endIndex));
}
}
感谢任何建议/帮助
【问题讨论】: