From c505389beff6a8966ece77c2e93a6ef81b449725 Mon Sep 17 00:00:00 2001 From: Xiao Z <97772488+learning1112@users.noreply.github.com> Date: Thu, 5 Sep 2024 16:08:17 +0800 Subject: [PATCH] Update 7.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 如果不限制dataset_copy的中元素数量的话,会报错 --- docs/ml/7.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ml/7.md b/docs/ml/7.md index 3c1132e9..15eb0e79 100644 --- a/docs/ml/7.md +++ b/docs/ml/7.md @@ -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: # 这里不能用 if,if 只是在第一次判断时起作用,while 执行循环,直到条件不成立 + while len(fold) < fold_size and len(dataset_copy) > 0: # 这里不能用 if,if 只是在第一次判断时起作用,while 执行循环,直到条件不成立            # 有放回的随机采样,有一些样本被重复采样,从而在训练集中多次出现,有的则从未在训练集中出现,此为自助采样法。从而保证每棵决策树训练集的差异性             index = randrange(len(dataset_copy)) # 将对应索引 index 的内容从 dataset_copy 中导出,并将该内容从 dataset_copy 中删除。