Machine Learning Basics
How machines learn from data — supervised, unsupervised, and reinforcement learning
What is Machine Learning?
Machine Learning (ML) is a subset of AI where computers learn patterns from data without being explicitly programmed for every scenario.
Traditional Programming vs Machine Learning
Traditional Programming: Rules + Data → Answers
Machine Learning: Data + Answers → Rules
Instead of writing the rules, you provide examples and the machine learns the rules on its own.
Types of Machine Learning
Supervised Learning
The model learns from labeled data — each training example has an input and the correct output.
Examples:
- Spam detection (email → spam/not spam)
- House price prediction (features → price)
- Image classification (image → "cat" or "dog")
Think of it like learning with an answer key.
Unsupervised Learning
The model finds patterns in unlabeled data — no correct answers provided.
Examples:
- Customer segmentation (grouping similar shoppers)
- Anomaly detection (finding unusual transactions)
- Recommendation systems ("users like you also bought...")
Think of it like finding patterns without a teacher.
Reinforcement Learning
The model learns by trial and error — receiving rewards for good actions and penalties for bad ones.
Examples:
- Game-playing AI (AlphaGo, chess engines)
- Robot navigation
- Self-driving cars
The ML Workflow
- Collect Data — Gather relevant, quality data
- Prepare Data — Clean, format, and split into training/test sets
- Choose Model — Select an algorithm appropriate for the problem
- Train — Feed training data to the model
- Evaluate — Test on unseen data to measure accuracy
- Deploy — Use the model in real applications
Simple Example in Python
Here's how a simple ML model works conceptually:
Simple Pattern Learning
This is a very simple example, but it demonstrates the core idea: learn patterns from data, make predictions on new data.
Check Your Understanding
In supervised learning, what does the training data include?
Check Your Understanding
Which type of learning uses rewards and penalties?