Let's mlxtend it!

Ensemble Methods in Python

Román de las Heras

Data Scientist, Appodeal

Mlxtend

mlxtend-logo

  • Machine Learning Extensions
  • Utilities and tools for Data Science tasks:
    • Feature selection
    • Ensemble methods
    • Visualization
    • Model evaluation
  • Intuitive and friendly API
  • Compatible with scikit-learn estimators
1 Raschka, Sebastian (2018) MLxtend: Providing machine learning and data science utilities and extensions to Python's scientific computing stack: https://rasbt.github.io/mlxtend/
Ensemble Methods in Python

Stacking implementation from mlxtend

stackingclassification_overview.png

Characteristics:

  • Individual estimators are trained on the complete features
  • The meta-estimator is trained using the predictions as the only meta-features
  • The meta-estimator can be trained with labels or probabilities as target
Ensemble Methods in Python

StackingClassifier with mlxtend

from mlxtend.classifier 
    import StackingClassifier
# Instantiate the 1st-layer classifiers
clf1 = Classifier1(params1)
clf2 = Classifier2(params2)
...
clfN = ClassifierN(paramsN)
# Instantiate the 2nd-layer classifier
clf_meta = ClassifierMeta(paramsMeta)
# Build the Stacking classifier
clf_stack = StackingClassifier(
   classifiers=[clf1, clf2, ... clfN],
   meta_classifier=clf_meta,
   use_probas=False,
   use_features_in_secondary=False)
# Use the fit and predict methods
# like with scikit-learn estimators
clf_stack.fit(X_train, y_train)
pred = clf_stack.predict(X_test)
Ensemble Methods in Python

StackingRegressor with mlxtend

from mlxtend.regressor 
    import StackingRegressor
# Instantiate the 1st-layer regressors
reg1 = Regressor1(params1)
reg2 = Regressor2(params2)
...
regN = RegressorN(paramsN)
# Instantiate the 2nd-layer regressor
reg_meta = RegressorMeta(paramsMeta)
# Build the Stacking regressor
reg_stack = StackingRegressor(
   regressors=[reg1, reg2, ... regN],
   meta_regressor=reg_meta,
   use_features_in_secondary=False)
# Use the fit and predict methods
# like with scikit-learn estimators
reg_stack.fit(X_train, y_train)
pred = reg_stack.predict(X_test)
Ensemble Methods in Python

Let's mlxtend it!

Ensemble Methods in Python

Preparing Video For Download...