Update 7.md

如果不限制dataset_copy的中元素数量的话,会报错
This commit is contained in:
Xiao Z
2024-09-05 16:08:17 +08:00
committed by GitHub
parent c248065a92
commit c505389bef

View File

@@ -156,7 +156,7 @@ def cross_validation_split(dataset, n_folds):
fold_size = len(dataset) / n_folds
for i in range(n_folds):
fold = list() # 每次循环 fold 清零,防止重复导入 dataset_split
while len(fold) < fold_size: # 这里不能用 ifif 只是在第一次判断时起作用while 执行循环,直到条件不成立
while len(fold) < fold_size and len(dataset_copy) > 0: # 这里不能用 ifif 只是在第一次判断时起作用while 执行循环,直到条件不成立
           # 有放回的随机采样,有一些样本被重复采样,从而在训练集中多次出现,有的则从未在训练集中出现,此为自助采样法。从而保证每棵决策树训练集的差异性            
index = randrange(len(dataset_copy))
# 将对应索引 index 的内容从 dataset_copy 中导出,并将该内容从 dataset_copy 中删除。