What is Machine Learning?
Traditional programming:Why Machine Learning?
Machine learning is useful when:- Rules are too complex
- Huge amounts of data exist
- Patterns continuously change
- Manual programming becomes difficult
- Netflix recommendations
- Self-driving cars
- Fraud detection
- Face recognition
- ChatGPT
- YouTube recommendations
Machine Learning Pipeline
Typical workflow:Types of Machine Learning
Machine Learning mainly has three types:1. Supervised Learning
What is Supervised Learning?
The model learns from labeled data. Labeled data:Types of Supervised Learning
Two major types:Regression
Predicts continuous numerical values. Examples:- House price prediction
- Stock price prediction
- Temperature prediction
- Sales forecasting
- Linear Regression
- Random Forest Regressor
- XGBoost
- Decision Tree Regressor
Classification
Predicts categories/classes. Examples:- Spam or Not Spam
- Disease Detection
- Fraud Detection
- Cat vs Dog
- Logistic Regression
- Decision Trees
- Random Forest
- SVM
- Neural Networks
Supervised Learning Flow
| Hours Studied | Marks |
|---|---|
| 2 | 40 |
| 4 | 60 |
| 6 | 75 |
Advantages
- Easy to evaluate
- High accuracy with enough labeled data
- Clear target output
Disadvantages
- Requires large labeled datasets
- Labeling data is expensive
- Can overfit
2. Unsupervised Learning
What is Unsupervised Learning?
Learns from unlabeled data. No correct outputs exist. Input:Types of Unsupervised Learning
Main categories:Clustering
Groups similar data points. Example: Customer segmentation:- K-Means
- DBSCAN
- Hierarchical Clustering
- Customer segmentation
- Fraud detection
- Image segmentation
Dimensionality Reduction
Reduces features while preserving information. Example: Dataset:- PCA
- t-SNE
- Faster training
- Visualization
- Noise reduction
Association Rule Learning
Finds relationships among items. Example:- Product recommendation
- Market basket analysis
- Apriori
- FP Growth
Advantages
- No labeled data needed
- Finds hidden patterns
Disadvantages
- Hard to evaluate
- Interpretation may be difficult
3. Reinforcement Learning (RL)
What is Reinforcement Learning?
Learning by interacting with an environment. Agent learns through:RL Components
Agent
The learner Examples:Environment
Where agent acts. Examples:State
Current situation. Example:Action
What agent can do. Example:Reward
Feedback after action. Example:Reinforcement Learning Flow
Example: Self-driving Car
State:Algorithms
- Q-Learning
- Deep Q Network (DQN)
- SARSA
- PPO
- Policy Gradient
Applications
- Robotics
- Self-driving vehicles
- Game AI
- Trading systems
- Recommendation systems
Advantages
- Learns automatically
- Handles complex environments
Disadvantages
- Requires large training time
- High computational cost
Comparison of ML Types
| Feature | Supervised | Unsupervised | Reinforcement |
|---|---|---|---|
| Labeled Data | Yes | No | Reward Signal |
| Goal | Predict output | Find patterns | Maximize reward |
| Example | Spam detection | Customer grouping | Self-driving cars |
| Output | Prediction | Groups/patterns | Actions |
Important ML Terms
Features
Input variables used for prediction. Example:Labels
Expected output. Example:Dataset
Collection of records. Example:| Area | Bedrooms | Price |
|---|---|---|
| 1200 | 3 | 25L |
| 1500 | 4 | 35L |
Training Data
Data used to train model.Test Data
Data used to evaluate model.Model
Mathematical representation learned from data.Prediction
Output produced by model.Overfitting
Model memorizes training data. Problem:Underfitting
Model fails to learn patterns. Problem:Train / Validation / Test, Overfitting, Bias–Variance Tradeoff
Why Do We Split Data?
Suppose we train a model using all available data:Dataset Split
Usually:Train Dataset
What is it?
Training data is used to teach the model patterns. Example: House Price Dataset:| Area | Bedrooms | Price |
|---|---|---|
| 1200 | 3 | 25L |
| 1500 | 4 | 35L |
| 1800 | 4 | 40L |
Purpose
- Learn relationships
- Update model weights
- Fit the model
Example
Validation Dataset
What is it?
Validation data is used during training to check model performance and tune settings. Model does not learn from this data.Purpose
Used for:- Hyperparameter tuning
- Model selection
- Detecting overfitting
Example
Try different values:Test Dataset
What is it?
Test data evaluates final performance. The model should never see test data during training.Purpose
Measures:Example:
Complete Flow
Train-Test Split Using Scikit-Learn
Code:Train / Validation / Test Split
Code:Overfitting
What is Overfitting?
The model memorizes training data instead of learning general patterns.Example: Training accuracy:
Graph intuition:
Causes
- Very complex model
- Small dataset
- Too many epochs
- Too many features
Symptoms
Example
Training data:| Hours | Marks |
|---|---|
| 1 | 30 |
| 2 | 40 |
| 3 | 50 |
| 4 | 60 |
Reduce Overfitting
1. More data
2. Regularization
Adds penalty. Examples:3. Dropout
Randomly removes neurons. Used in:4. Reduce complexity
Example:5. Early stopping
Stop training when validation performance stops improving.Example code:
Underfitting
What is Underfitting?
Model fails to learn patterns.Example: Training accuracy:
Symptoms:
Causes:
- Model too simple
- Too few features
- Insufficient training
Solutions:
Bias–Variance Tradeoff
This is one of the most important concepts in ML.What is Bias?
Bias measures error due to overly simple assumptions. High bias:Characteristics:
What is Variance?
Variance measures sensitivity to small data changes. High variance:Relationship
Bias–Variance Curve
Example
Suppose actual data:High Bias
Model:Balanced
Model:High Variance
Model:Visual Example with Polynomial Regression
Code:
Training vs Validation Loss
Good model:Overfitting: