Skip to content

Commit 8310684

Browse files
committed
Probably-saner divide-by-0 handling in AdaBoost.
1 parent 5e39c8f commit 8310684

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

learning.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def AdaBoost(L, K):
398398
"""[Fig. 18.34]"""
399399
def train(dataset):
400400
examples, target = dataset.examples, dataset.target
401+
epsilon = 1./(2*N)
401402
N = len(examples)
402403
w = [1./N] * N
403404
h, z = [], []
@@ -406,9 +407,8 @@ def train(dataset):
406407
h.append(h_k)
407408
error = sum(weight for example, weight in zip(examples, w)
408409
if example[target] != h_k(example))
409-
if error == 0:
410-
break
411-
assert error < 1, "AdaBoost's sub-learner misclassified everything"
410+
# Avoid divide-by-0 from either 0% or 100% error rates:
411+
error = max(epsilon, min(error, 1-epsilon))
412412
for j, example in enumerate(examples):
413413
if example[target] == h_k(example):
414414
w[j] *= error / (1. - error)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy