Courses Understanding Artificial Intelligence Machine Learning: How Computers Learn from Data

What is AI?

Machine Learning: How Computers Learn from Data

The paradigm shift from programming rules to learning patterns

12 min read · Lesson 3 of 18

A Different Kind of Programming

Traditional programming works like a recipe. A programmer writes explicit instructions: "If the email contains these words, mark it as spam." The computer follows the rules exactly. It never deviates, never improves, never adapts. If the spammers change their tactics, a human programmer must write new rules.

Machine learning flips this on its head. Instead of writing rules, you give the computer examples and let it figure out the rules on its own. Show it thousands of emails labeled "spam" and "not spam," and it discovers the patterns that distinguish them — patterns that might be too subtle or too numerous for a human to write out explicitly.

This is the fundamental shift that powers modern AI. Let's understand how it works.


The Dog and Cat Analogy

Imagine teaching a young child to tell the difference between dogs and cats. You don't sit them down and explain: "Dogs have longer snouts, cats have retractable claws, dogs' pupils are round while cats' are vertical slits..." That would be absurd. Instead, you show them examples.

"Look, that's a dog. That's a cat. Dog. Cat. Dog. Dog. Cat."

After enough examples, the child develops an intuitive ability to classify new animals they've never seen before. They can't necessarily articulate the rules they've learned — they just know. They've built an internal model from data.

Machine learning works the same way. You feed the system thousands or millions of labeled examples. The system adjusts its internal parameters until it can accurately classify new, unseen examples. The "rules" emerge automatically from the data.

Traditional programming: Human writes rules → Computer follows rules.
Machine learning: Human provides data → Computer discovers rules.

Three Flavors of Machine Learning

1. Supervised Learning

Supervised learning is the most common and intuitive type. You provide the system with labeled examples — inputs paired with correct outputs — and it learns to predict the output for new inputs.

Examples:

  • Email spam detection: Thousands of emails labeled "spam" or "not spam." The model learns to classify new emails.
  • House price prediction: Historical sales data (square footage, location, bedrooms → price). The model learns to estimate prices for new listings.
  • Medical imaging: X-rays labeled "normal" or "abnormal" by radiologists. The model learns to flag concerning images.

The "supervised" part means a human has provided the correct answers (labels) for the training data — like a teacher grading homework. The model learns by comparing its predictions to the known answers and adjusting itself to get closer.

2. Unsupervised Learning

Unsupervised learning works with data that has no labels. The system must find structure and patterns on its own.

Imagine dumping a thousand unlabeled photos on a table. Without being told what anything is, you'd naturally start grouping them — landscapes here, portraits there, food photos in this pile. You're finding structure without labels.

Examples:

  • Customer segmentation: Given purchase histories, the model groups customers into clusters with similar behavior — without being told what the groups should be.
  • Anomaly detection: Learning what "normal" network traffic looks like, then flagging anything unusual as a potential security threat.
  • Topic modeling: Analyzing thousands of articles and discovering that they cluster around topics like "politics," "sports," and "technology" — without being told those categories exist.

3. Reinforcement Learning

Reinforcement learning is learning by trial and error with feedback. An agent takes actions in an environment and receives rewards or penalties. Over time, it learns strategies that maximize its total reward.

Think of training a dog. You don't give the dog a manual. It tries things — sitting, jumping, rolling over — and when it does what you want, it gets a treat (reward). Over time, it learns which behaviors lead to treats. The dog is a reinforcement learning agent.

Examples:

  • Game playing: AlphaGo learned to play Go by playing millions of games against itself, receiving a reward for winning.
  • Robotics: A robot arm learning to pick up objects by trying repeatedly and getting rewarded for successful grasps.
  • RLHF for language models: Modern AI assistants are fine-tuned using reinforcement learning from human feedback — humans rate responses, and the model learns to produce responses humans prefer.

What Is a "Model"?

In machine learning, a model is the thing that gets built during training. It's a mathematical function — a set of numbers (called parameters) that transforms inputs into outputs.

Before training, a model is like a blank brain: it has structure but no knowledge. After training on data, its parameters have been tuned so that it captures patterns in the data. The trained model can then make predictions on new, unseen data.

A simple model might have a few dozen parameters. A large language model like Claude has billions of parameters — each one a number that was carefully adjusted during training to capture some aspect of how language works.


The Overfitting Trap

One of the most important concepts in machine learning is overfitting — and it has a perfect real-world analogy.

Imagine a student preparing for an exam by memorizing the answers to practice questions rather than understanding the underlying concepts. On the practice test, they score perfectly. But on the real exam, with different questions, they fail. They didn't learn the subject — they memorized specific answers.

Machine learning models can do exactly this. If a model is too complex or trains too long on too little data, it memorizes the training examples rather than learning the underlying patterns. It performs brilliantly on training data and terribly on new data.

Researchers fight overfitting with several techniques:

  • More data: The more examples, the harder it is to memorize them all.
  • Validation sets: Holding back some data to test whether the model generalizes.
  • Regularization: Mathematical techniques that penalize complexity and encourage simpler models.
  • Early stopping: Halting training before the model starts memorizing.
The goal of machine learning is not to perfectly recall the training data. It's to learn patterns that generalize to data the model has never seen before. This distinction — memorization vs. generalization — is at the heart of the field.

Why This Matters

Machine learning is the foundation upon which all modern AI is built. Large language models, image generators, self-driving cars, speech recognition — they all learn from data rather than following hand-crafted rules.

Understanding the basics of how machines learn helps you use AI tools more effectively. When you know that a model learned from data, you can anticipate its strengths (patterns that appeared frequently in training data) and its weaknesses (unusual situations it hasn't seen before). You can ask better questions, interpret results more accurately, and avoid the trap of treating AI as infallible.


Key Takeaways

  • Machine learning lets computers learn patterns from data instead of following hand-written rules.
  • Supervised learning uses labeled examples (input + correct answer). Unsupervised learning finds patterns without labels. Reinforcement learning learns through trial, error, and reward.
  • A model is the mathematical function that emerges from training — it transforms inputs into predictions.
  • Overfitting happens when a model memorizes training data instead of learning generalizable patterns — like a student memorizing answers instead of understanding concepts.
  • All modern AI — from language models to image recognition — is built on machine learning principles.
Ask about this lesson