Last time on Supervised Learning’s Got Talent, we were introduced to the talented decision maker of the show, Logistic Regression.

Today, we’re going to branch out and meet our next Supervised Learning contestant. This contestant, like Logistic Regression, is also skilled at making decisions, but the difference is?

They are a lot more detective-like in their process.

Introducing the Decision Tree!

Decision Tree. They may not produce oxygen, but they sure make some definitive calls!

🌳 Decision Tree - β€œThe Overthinking Oracle”

Remember how Logistic Regression is good at making decisions? Well, Decision Trees do this too (I mean, it’s right in their name, right?), but with a key difference:

Decision Trees ask a lot of questions before getting to a decision.

Imagine that you’re trying to decide whether to go out for ice cream. What are you going to do? You’ll probably ask a series of questions:

  • β€œIs the ice cream shop even open?” (Yes/No)

  • β€œDo I have money?” (Yes/No)

  • β€œAm I willing to deal with the guilt later?” (Yes/No)

Notice how each question is relevant to the decision? That’s exactly how a Decision Tree works!

It’s literally a flowchart of questions that leads to a decision or a prediction.

At their core, Decision Trees break your data into smaller and smaller chunks by asking yes/no questions at every levelβ€”like a nosy neighbor who won't stop until they know everything about your weekend.

πŸ€– Components Of A Decision Tree

Root Node: The topmost node representing the most important feature that splits the data first.

Internal Nodes: These are points where the tree makes decisions based on certain features. Each node asks a yes/no question to help further divide the data! Kind of like mini crossroad signs within the tree.

Branches: These are the paths you follow after answering a question at a node. They lead you to the next node/outcome, like following a breadcrumb trail.

Leaf Nodes: These nodes provide the final decision/result. Think of them as the end of the trail where you get your answer or prediction, such as classifying data or predicting a value.

Decision Tree: The ultimate family tree for data nerds.

Let’s say you’re trying to decide what show to watch on Netflix.

It all starts at the Root Node, with a big question like β€œAm I feeling adventurous?”

Based on your answer (that’s a branch!), you travel down to an Internal Node for another question, say, β€œIs my partner awake?”

You keep following branches through more internal questions until you land on a Leaf Node - that’s your definitive choice, such as β€œRewatch Game Of Thrones!”.

Here’s yet another example of the Decision Tree in action:

If you’re intuitive, you may say to yourself: Okay, yeah, great. Decision Trees ask lots of questions, but how do they know whichΒ question to ask next?

The answer to that is something called Information Gain and GINI Index.

πŸ“š Information Gain

Information Gain is all about finding the question that makes your data less confusing. It’s based on the concept of Entropy: the measurement of how messy your data is. Here’s the formula:

Entropy: Math’s fancy way of saying β€œIt’s a hot mess in here.”

  • pi
    β†’ This is the proportion (percentage) of things in a group.
    Example: If 7 out of 10 nuts are tasty, pi = 0.7

  • log⁑2(pi)
    β†’ This asks: How surprising is it to find this thing?
    The lower the probability, the more surprising it is.

  • Multiply: pi Γ— log⁑2(pi)
    β†’ This combines: how common something is Γ— how surprising it is.

  • Sum them all up (Ξ£)
    β†’ Add this up for all categories (like tasty nuts and yucky nuts).

  • Put a minus sign in front (–)
    β†’ This flips the negative result to positive because entropy should always be positive.

✍️ GINI Index

One more thing I want to show you is something called the GINI Index. It measures how mixed or impure a dataset is.

While Information Gain asks, β€œHow much cleaner did I make this data?”, the GINI Index asks, β€œHow clean is this pile?”

It measures impurity directly, by following this equation:

Believe it or not, this equation tells you how mixed up your life really is.

  • pi = the probability (or proportion) of class i in the dataset.

  • Sum βˆ‘ = add this up for all classes.

  • pi2 = multiply each class’s probability by itself.

  • Subtract from 1 = this gives you the impurity.

πŸ‘¨β€πŸ’» Coding Exercise + Practice Quiz + Visual PDF

And that’s the Decision Tree. The best way to actually make this stick is to get your hands on it. Run the code, and test your knowledge.

Let’s now decide to practice.

logo

Ready to stop reading about machine learning and start building it? 🀝

Reading about machine learning is one thing. Building it is another. Every week you'll get a complete ML Practice Pack designed to help you turn concepts into real skills.

Unlock Today's Practice Pack

What You Unlock:

  • πŸ’» Build real machine learning projects step-by-step in a guided coding environment.
  • 🧠 Test your knowledge with a quiz before moving to the next lesson.
  • πŸ“• Never forget the key concepts with visual guides designed for quick review.

Reply

Avatar

or to participate