Intorduction To Machine
Learning
Why ML?
What is Machine
Learning?
Machine Learning (ML) is a method of
teaching computers to learn from data
and make decisions or predictions
without being explicitly programmed.
• ML learns patterns from past data to
make decisions on new data.
• It mimics the way humans learn from
experience.
• Example: An email service learns
from previous spam emails to filter
future spam.
Why do we need ML?
ML is needed when writing manual rules is
impossible or inefficient.
• Large & complex data patterns (like images,
voice, behavior).
• Faster and more accurate than rule-based
systems in many scenarios.
• ML continuously improves as it receives more
data.
Real-World ML
Applications
ML is used in almost every field today.
• Healthcare – disease prediction, medical image
diagnosis.
• Finance – fraud detection, credit scoring.
• Education – student performance prediction,
personalized learning.
• Retail – recommendations (Amazon, Netflix).
• Transportation – self-driving cars, route
optimization.
Labelled vs Unlabeled
Dataset
Labelled Dataset
A labelled dataset has:
Input data (image/text/audio/etc.)
Correct answer (label) already attached
We know the truth.
Examples
Example Label
Cat image "Cat"
Email text "Spam" or "Not spam"
"Healthy" / "Rust" / "Scab" /
Leaf photo
"Rot"
Used in Supervised Learning
Unlabeled Dataset
An unlabeled dataset has:
Only input data
No correct answer given
Example Label
Random images ?
Customer purchase data ?
Sensor readings ?
Used in Unsupervised Learning
What is Training Data?
Training data is the data used to teach the model.
The model learns patterns from this data
In supervised learning, it includes input + labels
In unsupervised learning, it includes only input (no
labels)
Purpose: To make the model learn
Analogy: Like studying from textbooks and
practicing questions
What is Validation Data?
Validation data is used during training to tune/improve the
model.
Not used to teach the model directly
Used to check how well the model is learning
Helps to adjust:
learning rate
number of layers/trees
tuning hyperparameters
avoid overfitting
Purpose: To fine-tune the model
Analogy: Like taking mock tests while preparing for exams
What is Test Data?
Test data is used after the model has been trained
and finalized.
Never seen by the model during training
Used only once at the end to check final
performance
Measures true accuracy, F1, recall, etc.
Purpose: To evaluate the final model performance
Analogy: The final exam — model should not have
seen those questions before
Summary
Model sees it
Dataset When Used? Purpose during
training?
During
Training Teach model Yes
learning
Yes (but
Improve &
Validation During tuning not trained
tune
on it)
No (must
Final
Test After training remain
evaluation
unseen)
Quick Summary Table
Model sees it
Dataset When Used? Purpose during
training?
During
Training Teach model Yes
learning
Yes (but
Improve &
Validation During tuning not trained
tune
on it)
No (must
Final
Test After training remain
evaluation
unseen)
In Supervised Learning
Supervised learning = Data has labels
Goal
Model learns to predict correct outputs (labels).
Dataset What It Contains Why It Is Used
Model learns
Input + correct
Training Data patterns from
labels
labeled data
Tune
Input + correct hyperparameters
Validation Data
labels and prevent
overfitting
Measure final
Input + correct
Test Data accuracy on
labels
unseen data
Example: Classifying
emails
Email Text Label
"Congratulations, you won!" Spam
"Meeting tomorrow" Not Spam
All three sets (Train/Val/Test) contain labels
Analogy:
•Train = Teacher gives answers and trains you
•Validation = Practice test with key
•Test = Final exam with key (but you don’t see the key while
answering)
In Unsupervised Learning
Unsupervised learning = No labels
Goal
Model finds hidden patterns or groups.
How Train / Validation /
Test Work Here
Dataset What It Contains Why It Is Used
Input only (no Model discovers
Training Data
labels) patterns/clusters
Input only To tune
Validation Data
(optional) parameters (rare)
To evaluate
Test Data Input only cluster quality /
structure
Examples
Types of Machine
Learning
There are three main types of ML
based on how they learn from
data.
• Supervised Learning – learns
from labeled examples.
• Unsupervised Learning – finds
hidden patterns in unlabeled
data.
• Reinforcement Learning –
learns by trial, error and rewards.
Supervised Learning
Supervised learning uses labeled data (input →
output).
is defined as when a model gets trained on
a "Labelled Dataset". Labelled datasets have
both input and output parameters. In Supervised
Learning algorithms learn to map points between
inputs and correct outputs. It has both training
and validation datasets labelled.
Example: Consider a scenario where you have to
build an image classifier to differentiate between cats
and dogs. If you feed the datasets of dogs and cats
labelled images to the algorithm, the machine will
learn to classify between a dog or a cat from these
labeled images. When we input new dog or cat
images that it has never seen before, it will use the
learned algorithms and predict whether it is a dog or
a cat. This is how supervised learning works, and this is
particularly an image classification.
Classification Vs
Regression
Classification
Classification
deals with predicting categorical target variables,
which represent discrete classes or labels. For
instance, classifying emails as spam or not spam,
or predicting whether a patient has a high risk of
heart disease. Classification algorithms learn to
map the input features to one of the predefined
classes.
Classification Types
Here are some classification algorithms:
Logistic Regression
Support Vector Machine
Random Forest
Decision Tree
K-Nearest Neighbors (KNN)
Naive Bayes
Regression
Regression
Regression, on the other hand, deals with
predicting continuous target variables, which
represent numerical values. For example,
predicting the price of a house based on its size,
location, and amenities, or forecasting the sales
of a product. Regression algorithms learn to map
the input features to a continuous numerical
value.
Regression Types
Here are some regression algorithms:
Linear Regression
Polynomial Regression
Ridge Regression
Lasso Regression
Decision tree
Random Forest
Advantages Of
Supervised Machine
Learning
Supervised Learning models can have high
accuracy as they are trained on labelled data.
The process of decision-making in supervised
learning models is often interpretable.
It can often be used in pre-trained models which
saves time and resources when developing new
models from scratch.
Disadvantages
It has limitations in knowing patterns and may
struggle with unseen or unexpected patterns that
are not present in the training data.
It can be time-consuming and costly as it relies
on labeled data only.
Applications
Image classification: Identify objects, faces, and
other features in images.
Natural language processing: Extract information
from text, such as sentiment, entities, and
relationships.
Speech recognition: Convert spoken language into
text.
Recommendation systems: Make personalized
recommendations to users.
Predictive analytics: Predict outcomes, such as sales,
customer churn, and stock prices.
Medical diagnosis: Detect diseases and other
medical conditions.
Fraud detection: Identify fraudulent transactions.
APPLICATIONS
Autonomous vehicles: Recognize and respond to objects
in the environment.
Email spam detection: Classify emails as spam or not
spam.
Quality control in manufacturing: Inspect products for
defects.
Credit scoring: Assess the risk of a borrower defaulting on a
loan.
Gaming: Recognize characters, analyze player behavior,
and create NPCs.
Customer support: Automate customer support tasks.
Weather forecasting: Make predictions for temperature,
precipitation, and other meteorological parameters.
Sports analytics: Analyze player performance, make game
predictions, and optimize strategies.
Unsupervised Learning
Unsupervised models find hidden structure in
unlabeled data.
Unsupervised learning is a type of machine learning
technique in which an algorithm discovers patterns
and relationships using unlabeled data. Unlike
supervised learning, unsupervised learning doesn't
involve providing the algorithm with labeled target
outputs. The primary goal of Unsupervised learning
is often to discover hidden patterns, similarities, or
clusters within the data, which can then be used for
various purposes, such as data exploration,
visualization,and more.
Explanation
Consider that you have a dataset that contains
information about the purchases you made from
the shop. Through clustering, the algorithm can
group the same purchasing behavior among you
and other customers, which reveals potential
customers without predefined labels. This type of
information can help businesses get target
customers as well as identify outliers
Types
There are two main categories of unsupervised
learning that are mentioned below:
Clustering
Association
Clustering
Clustering
is the process of grouping data points into clusters
based on their similarity. This technique is useful for
identifying patterns and relationships in data
without the need for labeled examples.
Here are some clustering algorithms:
K-Means Clustering algorithm
Association
Association
is a technique for discovering relationships
between items in a dataset. It identifies rules that
indicate the presence of one item implies the
presence of another item with a specific
probability.
Here are some association rule learning
algorithms:
Apriori Algorithm
Eclat
FP-growth Algorithm
Concept
Real-life
Concept Meaning
Example
“People who
Finds
buy bread also
Association relationships/patterns
buy peanut
between items
butter”
Grouping
Groups similar data
Clustering customers by
points without labels
behavior
Real Word Application
When you shop on Amazon and it says
“Frequently bought together” — that's
Association.
When Netflix groups users into similar taste groups
— that's Clustering.
Advantages
It helps to discover hidden patterns and various
relationships between the data.
Used for tasks such as customer segmentation,
anomaly detection, and data exploration.
It does not require labeled data and reduces the
effort of data labeling.
Disadvantages
Without using labels, it may be difficult to predict
the quality of the model's output.
Cluster Interpretability may not be clear and may
not have meaningful interpretations.
Application
Clustering: Group similar data points into clusters.
Anomaly detection: Identify outliers or anomalies
in data.
Recommendation systems: Suggest products,
movies, or content to users based on their
historical behavior or preferences.
Image and video compression: Reduce the
amount of storage required for multimedia
content.
Applications
Image segmentation: Segment images into
meaningful regions.
Community detection in social networks: Identify
communities or groups of individuals with similar
interests or connections.
Customer behavior analysis: Uncover patterns
and insights for better marketing and product
recommendations.
Content recommendation: Classify and tag
content to make it easier to recommend similar
items to users.
Reinforcement Learning
RL learns by interacting with the environment and
receiving feedback.
• Used in robotics, gaming, recommendation
systems, automation.
• Examples: AlphaGo game AI, self-driving cars,
YouTube recommendations.
ML Workflow
Steps followed to build ML models.
• 1. Problem Understanding
• 2. Data Collection & Preprocessing
• 3. EDA & Feature Engineering
• 4. Model Training
• 5. Evaluation
• 6. Deployment & Monitoring
Problem Understanding
(Define the Objective)
What happens here?
Clearly define the problem
Identify target output (classification / regression /
forecasting)
Understand business or real goal
Define success criteria & constraints
Questions to ask
Question Why it matters
What are we predicting? Define task type
Why are we predicting it? Links to business impact
What is the cost of being
Fraud → recall > accuracy
wrong?
Do we need explainability? Medical/finance require it
Real-World Examples
Student Dropout
Prediction
Item Value
Predict which students are
Goal
at risk of dropping out
Type Binary Classification
Retain students, support
Business Value
learning
Model must be fair &
Key Constraint
interpretable
Leaf Disease Detection
Item Value
Detect whether a plant leaf
Goal
is diseased
Type Image Classification
Helps farmers take action
Impact
early
Constraint Works on mobile app offline
Output of this step
A clear project statement &
evaluation direction.
2. Data Collection
What happens here?
Identify data sources
Gather raw data
Source Type Examples
LMS logs, attendance,
Internal
images
External Kaggle, APIs, open datasets
I
Where will the data come
from
Student Dropout
Data comes from:
Attendance system
LMS activity logs
Previous exam scores
Assignment submission history
Leaf Disease Detection
Data comes from:
Field images
Kaggle leaf datasets
Manually collected mobile phone images
3. Data Cleaning &
Preprocessing
What happens here?
Prepare the raw data:
Handle missing values
Fix incorrect labels
Remove duplicates
Normalize formats
Type Methods
Mean/median fill, model-
Missing Data
based imputation
Outliers IQR
Text/Image noise blurring, denoising
Train-test Split 80-20
Student Dropout
Missing attendance → fill by average
Remove duplicate student IDs
Fix inconsistent class codes
Leaf Disease Detection
Resize images to fixed size (e.g., 224×224)
Normalize pixel values 0–1
Remove blurry/broken images
4. Exploratory Data
Analysis (EDA)
Explore data patterns:
Distribution analysis
Correlations
Outlier check
Visualization
Tools
Excel, Pandas, Seaborn, Power BI
Insights
Student Dropout
Plot attendance vs dropout
Check correlation between LMS logins & grades
Look for seasonal trends: exams, holidays
Insights found:
Students with <60% attendance & <5 weekly LMS logins have high
dropout risk.
Leaf Disease Detection
View sample images per class
Check class imbalance
Count healthy vs rust vs scab samples
Insights:
Class imbalance: Rust images are fewer → apply augmentation.
5. Feature Engineering
What happens here?
Create meaningful features from raw data.
Type Example
Datetime Extract weekday/hour
Images CNN learns itself
Domain Features Business logic features
Feature Engineering —
“Creating New
Information
Definition:
The process of creating new features or
transforming existing ones to make your data
more useful for a model.
It’s about improving data quality
Examples
Engineered
Original Data Explanation
Feature
Month,
Extracting useful
Date DayOfWeek,
components
IsWeekend
Price & Revenue = Price Creating new
informative
Quantity * Quantity
variable
AgeGroup = <18, Binning numerical
Age
18-30, 30+ data
Word count, Derived NLP
Text column
Sentiment score features
Real-World Example
Feature Meaning
Login_freq LMS visits/week
Attendance_avg % attendance over term
Assignment_delay Avg. submission delay
Performance_trend Score improvement trend
Goal
Goal:
Make the model understand the underlying
pattern better
Improve predictive power
Feature Selection —
“Choosing the Most Useful
Subset”
Definition:
The process of selecting the most important
features that actually help in prediction and
removing irrelevant or redundant ones.
It’s about reducing noise and preventing overfitting
What does Feature
Selection do?
Now Feature Selection picks the best ones:
Selected:
Attendance trend
Weekly study avg
Performance improvement rate
Removed:
Favorite subject (not useful)
Student Roll number (no relation)
Raw daily hours (already captured in weekly
avg)
Feature Engineering vs
Feature Selection
Feature
Concept Feature Selection
Engineering
Choosing the
Creating new
most useful
Meaning features from raw
features out of all
data
available
Reduce
Make data more
Goal irrelevant/noisy
informative
features
Choosing only
Cooking: cutting,
best vegetables
mixing, seasoning
Analogy and discarding
ingredients to
bad ones before
improve taste
cooking
After creating
Before model
When done? features (or with
training
raw features)
New & improved Smaller, optimized
Output
dataset feature set
Feature Encoding —
“Making Features
Machine-Readable”
Definition:
The process of converting categorical or textual
data into numeric form so that algorithms can
interpret it.
It’s not about creating new features, but
representing existing ones numerically.
Examples
Method Example Use Case
Ordinal
Red→0, Blue→1,
Label Encoding categories
Green→2
(education level)
Gender: Nominal
One-Hot Encoding Male→[1,0], categories (no
Female→[0,1] order)
6. Model Selection &
Training
What happens here?
Pick models → Train → Cross-validate
Task Algorithms
Logistic Regression, Random
Tabular
Forest, XGBoost
CNNs, Transfer Learning
Images
(ResNet, AlexNet)
Real-World Example
Student Dropout
Models tried:
Logistic Regression (baseline)
Random Forest
XGBoost (best)
Leaf Detection
Models tried:
CNN (custom)
AlexNet (transfer learning)
EfficientNet (best)
Metrics
[Link] Evaluation
Problem Metrics
Classification F1, Recall, Precision, ROC-AUC
Regression MSE,MAE, RMSE,R2,Adjuted R2
Real-World Example
Student Dropout
• Accuracy is misleading → use Recall
• Goal: catch at-risk students
Recall improved from 62% → 89% after feature
tuning.
Leaf Detection
• Confusion matrix shows misclassified diseases
• F1 per class to judge imbalance
8. Model Deployment
Type Use
Batch Weekly student risk report
API Real-time diagnosis app
Real World Examples
Real-World Example
Student Dropout
Model runs weekly
Sends alert list to counselors
Dashboard built in Power BI
9. Monitoring &
Maintenance (MLOps)
What happens here?
Track performance
Detect model drift
Retrain with new data
Real-World Example
Student Dropout
If new semester patterns change → retrain
Leaf Detection
New diseases appear → add data & retrain
Parametric vs
Non-Parametric Models
Models differ in flexibility and data requirements.
• Parametric: Fixed structure (Linear Regression).
Fast, less data.
• Non-Parametric: Flexible structure (Decision
Trees, Neural Nets). Powerful but data hungry.
Parametric model (like
Linear Regression)
Imagine you’re trying to predict house prices based
on area, number of rooms, etc.
Parametric model (like Linear Regression)
You assume:
“Price increases in a straight line with area.”
You pick a formula upfront — something like
Price = 50,000 + 3000 × Area
Only 2 numbers (slope and intercept) describe the
whole pattern.
It’s like drawing a straight line through all the data,
no matter how many houses you have.
Simple, fast, needs less data
Not flexible — only fits simple shapes (like lines)
Parameters in Parametric
Models
Parametric models assume a fixed form (like a line
or curve).
Examples & their parameters:
Model Parameters Mean
Weights & intercept (slope &
Linear Regression
bias)
Logistic Regression Weights for each feature
All weights & biases of
Neural Networks
neurons
Probabilities (mean,
Naive Bayes
variance per class)
Non-parametric model
(like Decision Tree, k-
Nearest Neighbors)
You say:
“I won’t assume any fixed formula. Let the data
itself decide the shape.”
If the data is curved, jagged, or weird — the
model bends and adapts.
It’s like drawing a line that passes close to every
dot, no matter how wiggly it gets.
Very flexible — learns any shape
Needs more data, can overfit, slower to train
Parameters in Non-
Parametric Models
Non-parametric models do not assume a fixed form.
They increase parameters as data increases.
Examples & what counts
as “parameters”
Model What are the parameters?
The training dataset itself (no
k-Nearest Neighbors (kNN) learning step; stores all
points)
Tree splits (rules created
Decision Trees
from data)
Many decision trees & their
Random Forest
splits
Support vectors (data points
SVM (kernel version)
kept)
Covariance functions &
Gaussian Processes
data points
Real-World Student
Example
Parametric Non-Parametric
Task
Choice Choice
Predict exam
Linear Regression Random Forest
marks
Detect spam Logistic Regression SVM with RBF /
emails / NB XGBoost
Image CNN / Deep
Simple Neural Net
classification Learning
Softmax CNN / AlexNet /
Plant leaf disease
Regression EfficientNet
Random Forest /
Fraud detection Logistic Regression
XGBoost
ML Ethics & Fairness
Responsible AI ensures fairness, transparency, and
trust.
• Avoid bias (gender, caste, income).
• Use explainability tools (SHAP, LIME).
• Privacy & responsible data use.