0
0
ML Pythonml~10 mins

Stacking and blending 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 import the stacking classifier from scikit-learn.

ML Python
from sklearn.ensemble import [1]
Drag options to blanks, or click blank then click option'
AGradientBoostingClassifier
BStackingClassifier
CRandomForestClassifier
DVotingClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Importing VotingClassifier instead of StackingClassifier.
Importing RandomForestClassifier which is a single model, not stacking.
2fill in blank
medium

Complete the code to create a stacking classifier with logistic regression as the final estimator.

ML Python
stack = StackingClassifier(estimators=estimators, final_estimator=[1]())
Drag options to blanks, or click blank then click option'
ADecisionTreeClassifier
BRandomForestClassifier
CKNeighborsClassifier
DLogisticRegression
Attempts:
3 left
💡 Hint
Common Mistakes
Using a complex model like RandomForestClassifier as final estimator.
Using a base estimator instead of a final estimator.
3fill in blank
hard

Fix the error in the code to correctly fit the stacking classifier on training data.

ML Python
stacking_model = StackingClassifier(estimators=estimators, final_estimator=LogisticRegression())
stacking_model.[1](X_train, y_train)
Drag options to blanks, or click blank then click option'
Afit
Bpredict
Ctransform
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Calling predict before fitting the model.
Using transform which is for feature processing.
4fill in blank
hard

Fill both blanks to create a blending dataset by training base models and collecting their predictions.

ML Python
blend_data = np.zeros((X_val.shape[0], len(estimators)))
for i, (name, model) in enumerate(estimators):
    model.[1](X_train, y_train)
    blend_data[:, i] = model.[2](X_val)
Drag options to blanks, or click blank then click option'
Afit
Bpredict
Ctransform
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using transform instead of predict for collecting predictions.
Calling score instead of fit to train models.
5fill in blank
hard

Fill all three blanks to define a stacking classifier with two base models and a final estimator.

ML Python
estimators = [("rf", RandomForestClassifier()), ("svc", [1]())]
stack = StackingClassifier(estimators=estimators, final_estimator=[2]())
stack.fit([3], y_train)
Drag options to blanks, or click blank then click option'
ASVC
BLogisticRegression
CX_train
DDecisionTreeClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Using DecisionTreeClassifier instead of SVC as base model.
Passing y_train instead of X_train to fit.