Hi Reader,
Last week, I had an hour-long chat with my friend Ken Jee for his podcast. Starting tomorrow, you can watch the conversation on the Ken’s Nearest Neighbors YouTube channel!
When working on a Machine Learning problem, it’s always a good idea to try different types of models to see which one performs best.
However, you can also use a process called “ensembling” to combine multiple models. The goal is to produce a combined model, known as an ensemble, that performs better than any of the individual models.
The process for ensembling is simple:
The idea behind ensembling is that if you have a collection of individually imperfect models, the “one-off” errors made by each model are probably not going to be made by the rest of the models. Thus, the errors will be discarded (or at least reduced) when ensembling the models.
Here’s a simple example in which I ensembled Logistic Regression and Random Forests using scikit-learn’s VotingClassifier:
Notice that the accuracy of the ensemble (0.725) is significantly better than the accuracy of either individual model. (Check out the full code here.)
➡️ Ensembling is useful any time model accuracy (or another evaluation metric) is your highest priority. Keep in mind that the ensemble will be less interpretable than the individual models.
➡️ It’s ideal to include at least 3 models in the ensemble.
➡️ It’s important that all models you include are performing reasonably well on their own.
➡️ It’s best if the included models generate their predictions using different processes, since they will be likely to make different types of errors. (This is what makes Logistic Regression and Random Forests good candidates for ensembling!)
If you enjoyed this week’s tip, please forward it to a friend! Takes only a few seconds, and it really helps me out! 🙌
See you next Tuesday!
- Kevin
P.S. Gym rats vs data scientists
Did someone awesome forward you this email? Sign up here to receive data science tips every week!
Join 25,000+ aspiring Data Scientists and receive Python & Data Science tips every Tuesday!
Hi Reader, Next week, I’ll be offering a Black Friday sale on ALL of my courses. I’ll send you the details this Thursday! 🚨 👉 Tip #50: What is a "method" in Python? In Python, a method is a function that can be used on an object because of the object's type. For example, if you create a Python list, the "append" method can be used on that list. All lists have an "append" method simply because they are lists: If you create a Python string, the "upper" method can be used on that string simply...
Hi Reader, I appreciate everyone who has emailed to check on me and my family post-Helene! It has been more than 6 weeks since the hurricane, and most homes in Asheville (mine included) still don't have clean, running water. We're hopeful that water service will return within the next month. In the meantime, we're grateful for all of the aid agencies providing free bottled water, free meals, places to shower, and so much more. ❤️ Thanks for allowing me to share a bit of my personal life with...
Hi Reader, Regardless of whether you enrolled, thanks for sticking with me through the launch of my new course! 🚀 I've already started exploring topics for the next course... 😄 🔗 Link of the week git cheat sheet (PDF) A well-organized and highly readable cheat sheet from Julia Evans, the brilliant mind behind Wizard Zines! 👉 Tip #48: Three ways to set your environment variables in Python I was playing around with Mistral LLM this weekend (via LangChain in Python), and I needed to set an...