File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -398,6 +398,7 @@ def AdaBoost(L, K):
398
398
"""[Fig. 18.34]"""
399
399
def train (dataset ):
400
400
examples , target = dataset .examples , dataset .target
401
+ epsilon = 1. / (2 * N )
401
402
N = len (examples )
402
403
w = [1. / N ] * N
403
404
h , z = [], []
@@ -406,9 +407,8 @@ def train(dataset):
406
407
h .append (h_k )
407
408
error = sum (weight for example , weight in zip (examples , w )
408
409
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 ))
412
412
for j , example in enumerate (examples ):
413
413
if example [target ] == h_k (example ):
414
414
w [j ] *= error / (1. - error )
You can’t perform that action at this time.
0 commit comments