Neural Mastery
← Practice
AdaBoost Sample Weight Re-weightingeasy

AdaBoost Sample Weight Re-weighting

easy Classical ML from Scratch 10–15 min

NumPy allowed · plain Python earns 10 bonus points

Re-weight training samples based on classifier correctness in an AdaBoost boosting round.

Related Skills

Task

Implement adaboost_weight_update(sample_weights, y_true, predictions, alpha): compute unnormalized weight w_i * exp(-alpha * y_i * h_i) where y_i, h_i in {-1, 1}. Normalize weights so their sum equals 1.0. Round each float to 4 decimal places.

Function Signature

adaboost_weight_update(sample_weights: list[float], y_true: list[int], predictions: list[int], alpha: float) -> list[float]

Examples

Example 1: One mistake one correct
Input: sample_weights = [0.5, 0.5] y_true = [1, 1] predictions = [1, -1] alpha = 0.5
Output: [0.2689, 0.7311]
Example 2: All correct weights remain uniform
Input: sample_weights = [0.5, 0.5] y_true = [1, -1] predictions = [1, -1] alpha = 1
Output: [0.5, 0.5]

Constraints

  • sample_weights sum to approximately 1.0
  • y_true and predictions contain {-1, 1}
Python3Saved ✓
import math

def adaboost_weight_update(sample_weights: list[float], y_true: list[int], predictions: list[int], alpha: float) -> list[float]:
"""Update and renormalize AdaBoost sample distribution weights.
Round each float to 4 decimal places.
"""
pass

Case 1: One mistake one correct
Input: sample_weights = [0.5, 0.5] y_true = [1, 1] predictions = [1, -1] alpha = 0.5
Expected: [0.2689, 0.7311]
Case 2: All correct weights remain uniform
Input: sample_weights = [0.5, 0.5] y_true = [1, -1] predictions = [1, -1] alpha = 1
Expected: [0.5, 0.5]