From the course: Applied Machine Learning: Ensemble Learning

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Hands-on coding with StackingClassifier

Hands-on coding with StackingClassifier

- [Instructor] Okay, let's look an example of using stacking. Here's my code. I'm importing the base models that I'm going to use here. So I'm going to use a decision tree and k-nearest neighbors. And then from the ensemble module, I'm importing the stacking classifier. At this point, I'm going to make a list that has tuples of the name of the classifier and the classifier in that. In this case, we have a decision tree and k-nearest neighbors. Finally, we will throw those estimators into the stacking classifier, and there is our model. I've got a pipeline here. In this case, the pipeline is not including the model at the end, it's just being used for pre-processing. And I'm going to take the output of calling fit_transform from the pipeline. That's just going to pre-process the data. And I'm going to feed that into our model.fit. After that, I'm going to calculate the accuracy of our model, using model.predict, and then taking the pipeline to transform the test data. Let's see what…

Contents