Module 2: Machine Learning Fundamentals
2. What is Machine Learning?
Description
In this lesson you'll understand the fundamental difference between traditional programming and Machine Learning: in traditional programming, you write the rules and the system executes them; in Machine Learning, you provide examples (data) and the system learns the rules on its own. That difference is what explains why today you can have systems that recognize faces, recommend movies, filter spam or translate languages without anyone having written explicit rules for each case.
This matters because throughout the rest of the guide (and in the bootcamp) you'll hear "ML model", "train", "training data", "generalization". If you're not clear on what "learning from data" means, those terms will be black boxes. Here you build that conceptual foundation: what ML is, how it works at a high level, and why it's different from programming rules by hand.
The key difference: rules vs data
Traditional programming
In traditional programming (the kind taught in introductory programming courses), you write the rules explicitly. For example, to classify emails as spam:
if the email contains "free":
classify as spam
if the email has more than 3 exclamation marks:
classify as spam
if the sender is on a blacklist:
classify as spam
else:
classify as not-spam
You decide the rules. The system executes them. If the rules are bad or incomplete, the system fails. If a new type of spam appears that you didn't cover with your rules, the system doesn't detect it. To improve the system, you have to write more rules by hand.
Problem: In practice, writing all the rules by hand is impossible or very costly when the problem is complex. How do you write rules to recognize a cat in a photo? "If it has whiskers and pointy ears"? And what if the cat is facing away? And what if the photo is dark? You can't cover every case with hand-written rules.
Machine Learning
In Machine Learning, you don't write the rules. You give the system lots of examples (data) and tell it what the correct answer is in each case (where applicable, as in supervised learning). The system learns the rules on its own, adjusting internal parameters until its predictions match the correct answers you gave it.
For example, to classify emails as spam:
- You give the system 10,000 labeled emails: "this is spam", "this isn't spam", etc.
- The system looks for patterns: what do the spam ones have in common? What do the non-spam ones have in common?
- The system learns rules (represented internally, not as readable code): "If these words appear with this frequency, it's likely spam."
- When a new email arrives (not seen before), the system applies what it learned and predicts: "This is spam with 95% confidence."
Advantage: You don't have to write rules by hand. The system finds patterns you wouldn't have coded. If you give it more examples (more data), it can improve on its own.
Key difference: In traditional programming, you define the rules → the system executes them. In Machine Learning, you define the data (examples) → the system learns the rules.
Analogy: teaching vs showing examples
Think about teaching a child what a cat is.
Traditional programming (rules): You tell them: "A cat has 4 legs, whiskers, pointy ears, it meows, etc." You code the rules. If they see a cat without visible whiskers or facing away, they can get confused because you didn't cover that case.
Machine Learning (data): You show them 1,000 photos of cats and 1,000 photos of dogs, and tell them which is which. The child learns on their own what distinguishes a cat from a dog (face shape, ear size, posture, etc.). When they see a new photo, they can classify it because they learned the patterns from the examples.
That's Machine Learning: learning from examples (data), not from hand-written rules.
How does a machine "learn"?
Here comes the key question: if you don't give it explicit rules, how does it learn? The short answer: by adjusting internal parameters (numbers) until the system's predictions match the correct answers you gave it in the training data.
The basic Machine Learning flow
Training data → Learning algorithm → Model
New data → Model → Prediction
- Training data: Examples with known answers. E.g. emails labeled as spam or not-spam.
- Learning algorithm: A process that adjusts the model's internal parameters to minimize errors on the training data. E.g. "adjusting the weights of a neural network".
- Model: The result of learning. It's an internal representation (numbers, weights, structure) of the patterns the system found in the data. E.g. "a model that classifies emails".
- New data: Data not seen before. E.g. a new email arriving in your inbox.
- Prediction: The model applies what it learned to the new data and gives an answer. E.g. "This email is spam with 95% confidence."
Concrete example (spam filter):
- Training data: 10,000 emails, each labeled "spam" or "not-spam".
- Learning algorithm: For example, a classification algorithm (Naive Bayes, Logistic Regression, or a neural network).
- Model: After training, the model has internal parameters that represent "if these words appear with this frequency, the probability of spam is X".
- New data: A new email that says "Make money fast! Click here".
- Prediction: The model analyzes the words and predicts "spam" with high confidence.
You don't need to understand the algorithm's mathematical details; what matters is the flow: data → learning → model → prediction on new data.
Key Machine Learning concepts
1. Training data
These are the examples you use so the system learns. The more examples you have (and the more varied), the better the model learns. Without data, there's no ML.
Example: To train a model that recognizes cats in photos, you need thousands of photos of cats (and thousands of photos of non-cats, so the model learns the difference).
2. Model
It's the result of learning: an internal representation of the patterns the system found in the data. The model can be simple (e.g. a linear equation with a few parameters) or complex (e.g. a neural network with millions of parameters).
Analogy: The model is like a "learned rulebook" that the system uses to make predictions. You didn't write it; the system learned it from the data.
3. Prediction / inference
It's when you use the already-trained model to give answers about new data. E.g. "Is this new email spam?" → the model predicts "yes" or "no".
In the industry, the term inference is used more often for this phase: the model infers the answer based on what it learned.
4. Generalization
It's the model's ability to work well on data not seen during training. A good model generalizes; a bad model only memorizes the training data and fails on new data.
Example: If you train a spam model with 10,000 emails and then give it a new email (not among those 10,000), the model should classify it correctly. If it only "memorized" the 10,000 emails and fails on new emails, it doesn't generalize well.
5. Overfitting
It happens when the model fits the training data too closely and loses its ability to generalize. It memorizes the examples instead of learning general patterns.
Analogy: It's like studying by memorizing specific questions from an exam without understanding the concepts; on the real exam with different questions, you fail.
6. Underfitting
It happens when the model is too simple and doesn't capture the patterns in the data. It doesn't learn enough, either in training or on new data.
Analogy: It's like studying only superficially; you don't even understand the examples you were given properly, let alone apply them to new cases.
Why this matters for an AI Engineer
When you work as an AI Engineer, you don't train models from scratch in most cases; you use already-trained models (from OpenAI, Anthropic, Google, Meta, etc.) via APIs. But understanding what ML is and how the flow works (data → model → prediction) helps you:
-
Understand what the model does: When you call the OpenAI API (GPT-4), you're using a model that learned from massive text data. That explains why it generates coherent text and why it sometimes hallucinates (because it learned from data that can have errors or biases).
-
Reason about limits: A model can only predict within the domain it was trained on. If you train a model with emails in English, it won't work well with emails in Chinese. If you train a model with photos of cats and dogs, it won't recognize horses. Understanding that keeps you from assuming capabilities the model doesn't have.
-
Design systems with those limits in mind: If the model can hallucinate (because it learned from data that can have errors), you design RAG (Retrieval-Augmented Generation) to connect it to verified documents. If the model has a finite context (context window), you design the system to summarize or bound the information you pass to it.
-
Communicate with product and business: Being able to explain "the model learned from data up to date X" or "the model was trained with Y type of examples" lets you justify design decisions and expectations.
Examples of Machine Learning in products
To lock in the idea, here are concrete examples of ML in products you use:
-
Spam filter (Gmail, Outlook): A model trained on millions of emails labeled as spam or not-spam. When a new email arrives, the model predicts whether it's spam.
-
Recommendations (Netflix, Spotify, Amazon): A model trained on user history (what you watched, what you listened to, what you bought). When you open the app, the model predicts what you'd like to watch/listen to/buy.
-
Speech recognition (Siri, Alexa, Google Assistant): A model trained on millions of audio recordings labeled with the corresponding text. When you speak, the model predicts what you said (it converts audio into text).
-
Machine translation (Google Translate, DeepL): A model trained on millions of sentence pairs (English-Spanish, English-French, etc.). When you write a sentence in English, the model predicts the translation in Spanish.
-
Image recognition (Google Photos, Facebook): A model trained on millions of labeled photos (cat, dog, person, car, etc.). When you upload a photo, the model predicts what's in it.
All of these are Machine Learning: systems that learned from data and make predictions on new data. There are no hand-written rules for each case; the model learned the patterns from the examples.
Key differences: traditional programming vs Machine Learning
| Aspect | Traditional Programming | Machine Learning |
|---|---|---|
| Rules | You write them explicitly | The system learns them from data |
| Input | Code (if-then-else, functions) | Data (labeled examples or not) |
| Output | A program that executes fixed rules | A model that makes predictions |
| Improvement | You modify the code by hand | You provide more data and retrain the model |
| Complex cases | Difficult/impossible (e.g. recognizing cats) | Feasible if you have enough data |
| Explainability | High (you wrote the rules) | Medium-Low (the model learned patterns, not readable rules) |
Frequently asked questions
So is Machine Learning "magic"?
No. It's math and algorithms: the system adjusts internal parameters (numbers) to minimize errors on the training data. It seems "magical" because you don't see the explicit rules; but internally they're mathematical operations on matrices of numbers (weights, biases, etc.).
Can any problem be solved with ML?
No. ML works well when:
- You have a lot of data (examples).
- The problem has patterns the system can learn.
- You don't need perfect explainability (e.g. in critical systems like medicine or legal, explicit rules are sometimes preferred).
If you don't have data, ML is useless. If the problem is simple and you can write clear rules (e.g. calculating taxes), traditional programming is more efficient.
Does the model always get it right?
No. The model makes predictions based on what it learned; it can be wrong. The model's quality depends on:
- The quantity and quality of the training data.
- The complexity of the problem.
- The model's architecture (simple vs complex).
That's why critical applications use human oversight or external verification.
What happens if the training data has errors or biases?
The model learns from the data you give it. If the data has errors, the model learns those errors. If the data has biases (e.g. photos of cats only against a white background), the model may not work well with different backgrounds. That's why data quality is critical.
How much data do I need?
It depends on the problem. For simple problems (e.g. classifying 2 categories), thousands of examples can be enough. For complex problems (e.g. recognizing objects in photos, understanding language), millions or billions of examples are used. LLMs (GPT, Claude, etc.) are trained on terabytes of text.
Common mistakes when understanding Machine Learning
1. Confusing "model" with "code"
Mistake: Thinking the model is code you wrote.
Reality: The model is the result of learning: parameters (numbers) that represent patterns learned from the data. You didn't write those parameters; the learning algorithm adjusted them.
2. Believing the model "understands"
Mistake: Thinking the model "understands" the problem the way a human does.
Reality: The model finds statistical patterns in the data; it has no consciousness or real understanding. It can predict well without "understanding" the meaning (e.g. a model that translates languages learns correlations between words, not deep meaning).
3. Assuming "more data is always better"
Mistake: Thinking that just by giving more data the model will improve indefinitely.
Reality: More quality data helps; more low-quality data (with errors, biases, noise) can make the model worse. Also, there's a point of diminishing returns: after a certain volume of data, adding more doesn't improve things much.
4. Not distinguishing training from inference
Mistake: Confusing the learning phase (training) with the usage phase (inference).
Reality: Training is when the model learns from data (expensive, long); inference is when the already-trained model makes predictions (fast, cheap). As an AI Engineer, you almost always work in inference (using already-trained models via APIs).
5. Thinking ML is "intelligence" like human intelligence
Mistake: Treating ML as if it were AGI (general intelligence).
Reality: ML is narrow AI: very good at the specific tasks it was trained for, but it doesn't generalize to any intellectual task. A model that plays Go doesn't know how to translate languages; a model that recognizes cats doesn't know how to play chess.
Exercises
Exercise 1: Identify ML vs traditional programming
Classify each system as traditional programming or Machine Learning. Justify in one sentence.
- A calculator that adds two numbers.
- A system that recommends movies based on your history.
- A traffic light that switches from red to green every 60 seconds.
- A system that detects spam in emails.
- A machine translator (Google Translate).
See solution
- Traditional programming. The rule is explicit: "a + b". It doesn't learn anything from data.
- Machine Learning. It learns patterns from your history (what you watched, what you liked) and predicts what you'd like.
- Traditional programming. The rule is explicit: "switch every 60 seconds". It doesn't learn anything.
- Machine Learning (in most modern cases). It learns from examples of spam and non-spam; it predicts whether a new email is spam.
- Machine Learning. It learns from millions of sentence pairs (English-Spanish, etc.); it predicts the translation of a new sentence.
Exercise 2: The ML flow
Complete the Machine Learning flow:
_____ data → _____ algorithm → _____
New data → _____ → _____
See solution
Training data → Learning algorithm → Model
New data → Model → Prediction
Explanation:
- Training data: examples with known answers.
- Learning algorithm: a process that adjusts the model's parameters.
- Model: the result of learning (a representation of patterns).
- New data: data not seen before.
- Prediction: the model applies what it learned and gives an answer.
Exercise 3: Generalization
What does it mean for a model to "generalize well"? Write 2-3 sentences.
See answer guide
Possible guide: A model generalizes well when it works correctly on data not seen during training. That is, it doesn't just "memorize" the examples you gave it, but learns general patterns that it applies to new cases. For example, a spam model that generalizes well correctly classifies new emails (not among the 10,000 used for training), not just the ones it already saw.
Exercise 4: Overfitting vs Underfitting
Explain in one sentence the difference between overfitting and underfitting.
See solution
Overfitting: The model fits the training data too closely and loses its ability to generalize (it memorizes instead of learning general patterns).
Underfitting: The model is too simple and doesn't capture the patterns in the data (it doesn't learn enough, either in training or on new data).
Quick analogy: Overfitting = studying by memorizing specific questions; underfitting = studying only superficially without understanding anything.
Exercise 5: Why it matters for AI Engineering
Why does an AI Engineer need to understand what Machine Learning is, even if they don't train models from scratch? Write 2-3 reasons.
See answer guide
Possible guide:
- Understanding what the model does: Knowing that the model learned from data helps you reason about its capabilities and limits (e.g. if it was trained on text up to 2023, it doesn't know about events from 2024).
- Designing systems with limits in mind: If the model can hallucinate (because it learned from data that can have errors), you design RAG to verify responses; if it has finite context, you design summaries or bounding.
- Communicating with product and business: Being able to explain "the model learned from X data" or "the model was trained with Y examples" lets you justify design decisions and expectations about what it can and can't do.
Summary
In one sentence: Machine Learning is a type of AI where the system learns rules from data (examples), instead of you writing the rules explicitly.
Key points:
- Fundamental difference: Traditional programming = you write rules → the system executes them. Machine Learning = you provide data → the system learns rules → it makes predictions on new data.
- Basic flow: Training data → Learning algorithm → Model → Prediction on new data.
- Key concepts: Training data, model, prediction (inference), generalization, overfitting, underfitting.
- Why it matters for an AI Engineer: Understanding what ML is and how it works helps you reason about model limits, design systems that assume those limits, and communicate with product and business.
- Examples in products: Spam filter, recommendations, speech recognition, translation, image recognition: they all use ML (they learned from data).
- It isn't magic: They're algorithms that adjust parameters (numbers) to minimize errors on training data. It seems "magical" because you don't see explicit rules, but internally they're mathematical operations.
Connection with the rest of the module
In the following lessons you'll see types of Machine Learning:
- Lesson 03 (Supervised Learning): ML with labels (e.g. emails marked as spam or not-spam). The most common type.
- Lesson 04 (Unsupervised Learning): ML without labels (e.g. grouping customers into segments without knowing in advance what segments exist).
- Lesson 05 (Reinforcement Learning): ML with rewards (e.g. an agent that learns to play Go by winning games).
And the most important lesson for AI Engineering:
- Lesson 06 (Training vs Inference): The distinction between "training a model" (what OpenAI, Anthropic, Meta do) and "using an already-trained model" (what you do when you call an API). That distinction is the heart of your role.
Additional resources
-
Google ML Crash Course: Introduction to ML — Official introduction to ML with interactive examples. In English. Complements this lesson.
-
Coursera: Machine Learning Specialization (Andrew Ng) - Week 1 — The first week of the reference course; it covers what ML is and the difference from traditional programming. In English with subtitles.
-
IBM: What is Machine Learning? — Definition and examples of ML. In English. Useful for contrasting with this lesson.
-
3Blue1Brown: But what is a neural network? — A video that visually explains how neural networks learn (a type of ML). In English. It goes deeper in Module 3 but is useful for intuition.
-
Elements of AI – Chapter 3: Machine Learning — A free course in several languages (including Spanish); chapter 3 covers ML. Additional exercises to practice.
-
Fast.ai: Practical Deep Learning - Lesson 1 — The first lesson covers what ML is and why it matters. In English. More practical (with code) if you want to go deeper afterward.