Get startedGet started for free

A first attempt with mlxtend

It's time to start working with mlxtend! You'll continue using the app ratings dataset. As you have already built a stacked ensemble model using scikit-learn, you have a basis to compare with the model you'll now build with mlxtend.

The dataset is loaded and available to you as apps.

Let's see if mlxtend can build a model as good as or better than the scikit-learn ensemble classifier.

This exercise is part of the course

Ensemble Methods in Python

View Course

Exercise instructions

  • Instantiate a decision tree classifier with min_samples_leaf = 3 and min_samples_split = 9.
  • Instantiate a 5-nearest neighbors classifier using the 'ball_tree' algorithm.
  • Build a StackingClassifier passing: the list of classifiers, the meta classifier, use_probas=True (to use probabilities), and use_features_in_secondary = False (to only use the individual predictions).
  • Evaluate the performance by computing the accuracy score.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Instantiate the first-layer classifiers
clf_dt = ____(____, ____, random_state=500)
clf_knn = ____

# Instantiate the second-layer meta classifier
clf_meta = LogisticRegression()

# Build the Stacking classifier
clf_stack = ____
clf_stack.____

# Evaluate the performance of the Stacking classifier
pred_stack = ____
print("Accuracy: {:0.4f}".format(accuracy_score(y_test, pred_stack)))
Edit and Run Code