Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-137

AdaBoost Weight Update

Problem

Perform one AdaBoost weight update: w_i = w_i * exp(-alpha * y_i * pred_i), then normalize the weights to sum to 1.

Labels and predictions are in {-1, +1}. Empty input returns []; if the new weights sum to 0, return all zeros.

Hint

Misclassified samples get their weight multiplied by exp(alpha), correct ones by exp(-alpha).

Test cases

case 1
in: [[0.5,0.5],[1,1],[1,-1],0.5]
expected: [0.26894142136999516,0.731058578630005]
case 2
in: [[0.5,0.5],[1,1],[1,1],0.5]
expected: [0.5,0.5]
case 3
in: [[0.2,0.3,0.5],[1,-1,1],[-1,-1,1],1]
expected: [0.6487856442839394,0.13170538339352275,0.21950897232253794]
case 4
in: [[],[],[],1]
expected: []
Starter codePython
import math
def adaboost_weight_update(weights, y_true, y_pred, alpha):
    # Your code here
    pass

4 test cases · run your code against them in the editor