Hi Reader,
How's your January going? I've been playing a lot of PokΓ©mon (the card game) with my 7 year-old... actually I'm the one who's always bugging him to play π
Are you a PokΓ©mon fan? Meowscarada ex, anyone?
βIntroduction to Polars (Practical Business Python)
Have you heard of Polars? In short, it's a high-performance, memory-efficient alternative to pandas. If you're new to Polars, this blog post walks through basic Polars code and compares it to pandas.
When performing supervised Machine Learning, one of the keys to success is effective data preprocessing, which can require a lot of thought and planning.
However, there's a scikit-learn model which has two magical properties that significantly reduce your preprocessing burden. (And you've probably never even heard of it!)
It's called Histogram-Based Gradient Boosted Trees (HGBT). Here are its magical properties:
What exactly does that mean? I'll explain below! π
When your training data contains missing values, normally you have to impute all missing values as part of the data preprocessing step. (The only alternative is to drop samples or features with missing values, which can mean losing valuable training data!)
But if you use HGBT, it will handle the missing values without imputation or dropping any data!
Here's a minimal example from the scikit-learn documentation:
Here's a longer example from one of my videos.
Note: Decision Trees also support missing values as of scikit-learn 1.3, and Random Forests support missing values as of scikit-learn 1.4.
When your training data contains unordered categorical features, normally you have to one-hot encode them as part of the data preprocessing step.
But if you use HGBT, it will handle the categorical features without encoding!
Starting in scikit-learn 1.4, HGBT will also infer which features are categorical directly from the data types of a pandas DataFrame!
Here's an example from the scikit-learn documentation:
Here's a longer comparison of native categorical support versus one-hot encoding and ordinal encoding.
If you want to learn more HGBT, check out the scikit-learn user guide.
Or if you're new to scikit-learn, check out one of my FREE scikit-learn courses!
Did you like this weekβs tip? Please send it to a friend or share this link on social. It really helps me out! π
See you next Tuesday!
- Kevin
P.S. Microsoft Excel World Championship (with live commentary)β
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...