Last post we built a neural network from scratch. It worked, but it needed constant babysitting: learning rates, gradients, normalization. This time it’s an algorithm that’s much harder to break and often does better on tabular data: the Random Forest.
Still Pandas for the data and PyTorch logic for the mechanics, but a different strategy. Instead of one complex brain, we use a committee of 100 simple Decision Trees. If you missed how we prep the Titanic data, the full series is here: https://www.youtube.com/@WillGWithAI
The Decision Tree 🌲
A forest starts with a tree, and a Decision Tree is just a chain of yes/no questions.
The logic: Is the passenger male? If yes, was their ticket 3rd class?
The problem: A single tree is a perfectionist. It memorizes the training data so well that it falls apart on any passenger it hasn’t seen. That’s overfitting.
Thought Provoker: Ask one person for medical advice and they might be wrong. Ask 1,000 and take the most common answer, and you’re using the “Wisdom of the Crowd.” At what point does a group of simple thinkers beat one genius expert?
Bagging: Diversity Through Randomness 🎲
If all 100 trees saw the same thing, they’d be 100 clones. The fix is Bagging (Bootstrap Aggregating), plus a bit of extra randomness.
Each tree gets a random subset of passengers. And at every split, the tree only gets to choose from a random subset of features (like Age, Sex or Fare). At one split, Tree A might only get to pick between Age and Siblings. At another, Tree B might only get Fare and Pclass.
The result: The trees see different things, so they make different mistakes. Average their votes and the mistakes mostly cancel out.
Challenge: After watching the video, can you explain why we deliberately hide some columns at each split? What would happen if every tree got to split on “Sex” first?
Why the Forest Is So Stable 🏛️
Random Forests don’t much care if your data is noisy or you forgot to normalize.
Outliers: One passenger with a $500 ticket won’t wreck a Random Forest the way it can throw off a neural network’s gradients.
No babysitting: No exploding gradients, no hunting for a learning rate like exactly 2.0. You grow the trees and let them vote.
Thought Provoker: If forests are more stable and easier to build, why did we spend so long on neural networks? Are there problems a forest simply can’t “see”?
Picking the Right Tool 🌐
Building this Titanic predictor in 10 minutes made something click for me: “AI” isn’t one thing, it’s a toolbox. Sometimes you want the precision of a neural network. Sometimes you want a Random Forest that just works.
The trade-off: We hit high accuracy again, but traded mathematical elegance for logical voting.
Rule of thumb: For tabular data (rows and columns, like a spreadsheet), try a Random Forest first. It’s a strong baseline with very little tuning. Reach for a neural network when the data or the problem actually needs it.
I’m still surprised how much simpler this was than the NN training loop. Is simpler always better? Not always, but it’s a good place to start.