Practicing Machine Learning Interview Questions in Python
Lisa Stuart
Data Scientist
Linear relationship assumption (incorrect)
High complexity models:
# import modules
from sklearn.ensemble import BaggingClassifier
from sklearn.ensemble import AdaBoostClassifier
from xgboost import XGBClassifier
from vecstack import stacking
# Create list: stacked_models
stacked_models = [BaggingClassifier(n_estimators=25, random_state=123), AdaBoostClassifier(n_estimators=25, random_state=123)]
# Stack the models: stack_train, stack_test
stack_train, stack_test = stacking(stacked_models, X_train, y_train, X_test, regression=False, mode='oof_pred_bag',
needs_proba=False, metric=accuracy_score, n_folds=4, stratified=True, shuffle=True, random_state=0, verbose=2)
# Initialize and fit 2nd level model
final_model = XGBClassifier(random_state=123, n_jobs=-1, learning_rate=0.1, n_estimators=10, max_depth=3)
final_model_fit = final_model.fit(stack_train, y_train)
# Predict: stacked_pred
stacked_pred = final_model.predict(stack_test)
# Final prediction score
print('Final prediction score: [%.8f]' % accuracy_score(y_test, stacked_pred))
Algorithm | Function |
---|---|
Bootstrap aggregation | sklearn.ensemble.BaggingClassifier() |
Boosting | sklearn.ensemble.AdaBoostClassifier() |
XGBoost | xgboost.XGBClassifier() |
Technique | Bias | Variance |
---|---|---|
Bootstrap aggregation (Bagging) | Increase | Decrease |
Boosting | Decrease | Increase |
Which of the following statements is true about the three major techniques used for ensemble methods in Machine Learning? Select the statement that is true:
Which of the following statements is true about the three major techniques used for ensemble methods in Machine Learning? The correct answer is:
Which of the following statements is true about the three major techniques used for ensemble methods in Machine Learning?
Practicing Machine Learning Interview Questions in Python