How Machine Learning Works
Training, Models, and the Three Learning Paradigms
Machine learning is the engine behind modern AI. When people say "the model was trained on 10 million images," what does that actually mean? In this post, we will demystify the machine learning process – supervised learning, unsupervised learning, and reinforcement learning – with concrete examples.
1. The Core Idea – Learning a Function from Examples
Machine learning is about finding a function f that maps inputs (x) to outputs (y). You provide many examples of (x, y) pairs, and the learning algorithm finds f that approximates the relationship.
- House price prediction: Input x = square footage, bedrooms, location; Output y = sale price.
- Cat detector: Input x = image pixels; Output y = 1 if cat, 0 if not cat.
2. Supervised Learning – Learning from Labeled Data
The training data includes both inputs and the correct outputs (labels). The model learns to predict labels for new, unseen inputs.
- Classification (discrete output): spam detection (spam/not spam), medical diagnosis (disease/no disease).
- Regression (continuous output): price prediction, temperature forecasting.
How it works: start with random parameters, feed input through the model, compute the error (how far prediction is from truth), adjust parameters to reduce error, repeat millions of times.
3. Unsupervised Learning – Finding Hidden Patterns Without Labels
The training data has no labels. The model discovers structure, groupings, or patterns on its own.
- Clustering: Grouping similar customers by purchasing behavior.
- Anomaly detection: Finding unusual transactions in bank data (fraud detection) without labeled examples of fraud.
Why unsupervised? Labeled data is expensive to create. Unsupervised learning can extract value from unlabeled data.
4. Reinforcement Learning – Learning from Rewards and Punishments
An agent learns by interacting with an environment. It receives rewards (positive) or penalties (negative) and learns a policy that maximizes cumulative reward.
- AlphaGo: Plays millions of games against itself, receiving +1 for a win, -1 for a loss.
- Robotics: A robot arm receives a reward when it successfully grasps objects.
Key difference from supervised learning: there is no "correct" action label – only delayed rewards. The agent must balance exploring new actions and exploiting known good actions.
5. The Machine Learning Workflow
- Define the problem: What are we predicting? How will we measure success?
- Collect data: From databases, APIs, sensors, or manual labeling.
- Clean and preprocess data (often 80% of the work): Handle missing values, remove duplicates, normalize values, split into training set (80%) and test set (20%).
- Choose a model: Linear regression, decision tree, neural network, etc.
- Train the model.
- Evaluate on test set.
- Deploy and monitor. Real-world data changes over time (concept drift). Retrain periodically.
6. Overfitting and Underfitting
|
Condition |
What it means |
Symptoms |
|
Underfitting |
Model is too simple to capture the pattern. |
Poor performance on both training and test data. |
|
Overfitting |
Model memorizes the training data, including noise. |
Excellent on training, poor on test. Does not generalize. |
|
Good fit |
Model captures the true pattern without memorizing noise. |
Good on both training and test. |
Analogy: Studying for an exam. Underfitting = only studied the first chapter. Overfitting = memorized the exact wording of practice questions but fail on slightly different real questions. Good fit = understood the concepts and can answer new questions.
Summary
|
Term |
Definition |
|
Supervised learning |
Learning from input-output pairs (labeled data). |
|
Unsupervised learning |
Finding patterns in unlabeled data. |
|
Reinforcement learning |
Learning by trial and error with rewards/penalties. |
|
Training set |
Data used to adjust model parameters. |
|
Test set |
Held-out data to evaluate final performance. |
|
Overfitting |
Model memorizes training data but fails on new data. |
Review Questions
- You have a dataset of 1,000 medical images, each labeled "cancerous" or "benign." Which type of learning is this?
- Why is the test set kept separate from the training set?
- Explain overfitting in your own words. How can you detect it?