Foundations6 min read

What Is Machine Learning?

Teaching computers to learn from examples instead of following rigid rules
rule-based approach:Brittle Β· breaks on edge casesML approach:Flexible Β· improves with more datatraining time:Slow upfront Β· fast predictions after

Imagine you're teaching a toddler to tell cats from dogs. You don't sit them down and say, "If the ears are pointy AND the nose is small AND the tail curves upward, it's a cat." That would be insane. Instead, you just show them examples. "This is a cat. This is a dog. This is a cat." After enough examples, the kid gets it β€” even for animals they've never seen before.

That's the core idea behind machine learning. Instead of writing a mountain of if-else rules, you feed the computer data and let it figure out the patterns on its own.

The old way: rules, rules, rules

Traditional programming works like a recipe book. The programmer writes every single rule by hand:

  • If the email contains "free money" β†’ spam
  • If the email is from your contacts β†’ not spam
  • If there are more than 5 exclamation marks β†’ spam

This works... until spammers get creative. They start writing "fr33 m0ney" and your rules break. You patch one rule, they find another hole. It's an endless game of whack-a-mole.

The ML way: learn from examples

With machine learning, you take a different approach entirely. You gather thousands of emails that humans have already labeled as "spam" or "not spam." Then you say to the computer: "Here are the examples. Figure out the pattern yourself."

The computer crunches through the data and discovers patterns you might never have thought of β€” like the combination of certain words, the time of day, the sender's country, and dozens of other subtle signals. And when spammers change tactics? You just feed the model new examples and it adapts.

Your First ML Model (3 lines!)

from sklearn.tree import DecisionTreeClassifier
# Training data: [hours_studied, hours_slept]
# Labels: 0 = fail, 1 = pass
X = [[1, 4], [2, 5], [6, 8], [7, 7], [8, 9], [3, 3]]
y = [0, 0, 1, 1, 1, 0]
# Create and train the model
model = DecisionTreeClassifier()
model.fit(X, y)
# Predict: student who studied 5hrs, slept 7hrs
print(model.predict([[5, 7]])) # [1] = pass!
print(model.predict([[1, 3]])) # [0] = fail
Output
[1]
[0]

How does the computer actually "learn"?

Think of it like tuning a guitar. At first, the strings are way off β€” the model's predictions are terrible. But after each example, the model adjusts its internal settings a tiny bit to reduce the error. Example after example, adjustment after adjustment, the predictions get better and better.

This process is called training. The internal settings being tuned are called parameters (or weights). And the measure of how wrong the predictions are is called the loss.

The whole goal of training: minimize the loss.

The big picture

  1. Collect data β€” examples with known answers
  2. Train a model β€” let the algorithm find patterns
  3. Evaluate β€” test it on data the model hasn't seen
  4. Predict β€” use the trained model on new, real-world data

Key Metrics

πŸ“ Rule-Based System
Breaks when the world changes
Manual effort Every rule written by hand
πŸ€– ML Model
Adapts when you feed new examples
Training time Learns rules from data
🧠 Prediction Speed
Training is slow, predictions are fast
Fast Milliseconds per prediction
πŸ“Š Data Requirement
Garbage in, garbage out
Moderate to High More data = better model
Note: Machine learning isn't magic β€” it's pattern matching at scale. The computer doesn't "understand" cats or dogs. It just learns that certain pixel patterns tend to have the label "cat." No data, no learning. Bad data, bad learning.

Quick check

What's the main difference between traditional programming and machine learning?
Challenge

Continue reading