0
0
ML Pythonml~10 mins

Boosting concept in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple AdaBoost classifier using scikit-learn.

ML Python
from sklearn.ensemble import AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier

model = AdaBoostClassifier(base_estimator=[1], n_estimators=50, random_state=42)
model.fit(X_train, y_train)
Drag options to blanks, or click blank then click option'
AKNeighborsClassifier()
BRandomForestClassifier()
CDecisionTreeClassifier(max_depth=1)
DSVC()
Attempts:
3 left
💡 Hint
Common Mistakes
Using complex models like RandomForest or SVC as base estimators.
Not specifying max_depth=1 for the decision tree.
2fill in blank
medium

Complete the code to calculate the weighted error of a weak learner in boosting.

ML Python
weighted_error = sum(sample_weights * (predictions != y_true)) / [1]
Drag options to blanks, or click blank then click option'
Asum(sample_weights)
Blen(predictions)
Csum(y_true)
Dlen(sample_weights)
Attempts:
3 left
💡 Hint
Common Mistakes
Dividing by the number of samples instead of sum of weights.
Using sum(y_true) which is unrelated.
3fill in blank
hard

Fix the error in updating sample weights after a boosting iteration.

ML Python
sample_weights = sample_weights * np.exp([1] * (predictions != y_true))
sample_weights /= sample_weights.sum()
Drag options to blanks, or click blank then click option'
A1
B-alpha
Calpha
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive alpha which decreases weights for errors.
Using constants 1 or -1 which ignore alpha.
4fill in blank
hard

Fill both blanks to compute the alpha (learner weight) in AdaBoost.

ML Python
alpha = 0.5 * np.log((1 - [1]) / [2])
Drag options to blanks, or click blank then click option'
Aweighted_error
B1 - weighted_error
D1 + weighted_error
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping numerator and denominator.
Using incorrect expressions like 1 + weighted_error.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each weak learner to its alpha weight if alpha is positive.

ML Python
learner_weights = [1]: [2] for learner, [3] in zip(learners, alphas) if [2] > 0}
Drag options to blanks, or click blank then click option'
Alearner
Balpha
Dweight
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names like 'weight' or inconsistent names.
Not filtering by positive alpha.