0% found this document useful (0 votes)
1 views59 pages

Unit 2 - Supervised Learning

The document provides an overview of machine learning, including its definition, workflow, and various applications such as image recognition and healthcare. It details types of machine learning, including supervised, unsupervised, and reinforcement learning, along with specific algorithms like linear regression, logistic regression, and decision trees. Additionally, it covers evaluation metrics for both regression and classification models to assess their performance.

Uploaded by

ferdina0109
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views59 pages

Unit 2 - Supervised Learning

The document provides an overview of machine learning, including its definition, workflow, and various applications such as image recognition and healthcare. It details types of machine learning, including supervised, unsupervised, and reinforcement learning, along with specific algorithms like linear regression, logistic regression, and decision trees. Additionally, it covers evaluation metrics for both regression and classification models to assess their performance.

Uploaded by

ferdina0109
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MACHINE LEARNING

SYLLABUS OVERVIEW
INTRODUCTION TO MACHINE
LEARNING
Machine Learning is a branch of AI, and it’s a technique that allows computers to learn from
data and make decisions without explicit programming.

It works by identifying patterns in data and using them to make predictions.

It is used in areas such as:


• Image Recognition
• Speech Processing
• Language Translation
• Recommender Systems
MACHINE LEARNING WORKFLOW

New unseen
data

Training Data ML Algorithm ML Model Prediction

Input Learns patterns Stores Learned Output


patterns
Applications of Machine Learning
1. Google Search
Ranks the most relevant websites.
Uses user behavior and search patterns.
2. Social Media
Recommends posts, reels, and videos.
Learns user interests and preferences.
3. Product Recommendation
Suggests products based on previous purchases.
Example: Amazon, Flipkart.
4. Image Recognition
Identifies objects, people, or animals in images.
Example: Face Unlock, Google Photos.
5. Email Spam Detection
Classifies emails as Spam or Not Spam.
Filters unwanted emails automatically.
Applications of Machine Learning
6. Speech Recognition
Converts speech into text.
Example: Google Assistant, Siri, Alexa.
7. Healthcare
Predicts diseases and assists in diagnosis.
Analyzes medical images and patient data.
8. Fraud Detection
Detects suspicious banking or credit card
transactions.
Prevents financial fraud.
9. Predictive Analytics
Predicts future trends using historical data.
Used in sales forecasting and weather prediction.
STRUCTURED DATASET
Target / Label /
Eg: Loan status approval prediction dataset Class / Output

• Each row represents individual data sample


• Each column represents one feature (attribute)

Dataset = Features (input) + Target (output)


[independent [dependent
variable] variable]
FEATURE TYPES
Nominal Discrete
Categorical Features Numerical Features

Ordinal Continuous

Nominal: Categorical data with no order/ranking Discrete: Countable values (finite)


Eg: Gender: Male/Female; Eg: number of bedrooms, number of
Color of a Car: White/Black/Blue/Red Students, number of items in a cart.

Ordinal: Categorical data with a meaningful order Continuous: Measurable quantities


Eg: Customer Rating: Poor < Fair < Good < Excellent; (infinite)
• Disease Risk: Low < Moderate < High; Eg: Temperature, Height, House Price
• Size: Small < Medium < Large prediction
Types of Machine Learning

• Supervised Learning: Learns from labeled data where correct outputs are already known to make
predictions or classifications.
• Unsupervised Learning: Learns from unlabeled data by finding hidden patterns, similarities, or groups
automatically.
• Reinforcement Learning: Learns through trial and error by receiving rewards for correct actions and
penalties for wrong ones.
I. SUPERVISED LEARNING
The model is trained on a labeled dataset, meaning each input has a
corresponding known output. The goal is to learn a mapping rule to
predict outputs for new, unseen data.
• Predicts a continuous numerical value • Predicts a category / class
TYPES OF CLASSIFICATION

Binary Classification Multi-Class Classification

• Predicts one of two classes. • Predicts one of more than two classes.
• Output has only 2 possible categories. • Output has 3 or more categories.

Examples: Examples:
Loan Status → Approved / Rejected Disease Risk → Low / Moderate / High
Email → Spam / Not Spam Weather → Sunny / Rainy / Cloudy
Disease → Positive / Negative Grade → A / B / C / D
Student Result → Pass / Fail
LINEAR REGRESSION MODELS
• Linear regression is used to predict the value of a variable based on
the value of another variable.
• It is a type of supervised machine learning algorithm that computes
the linear relationship between a dependent variable and one or
more independent features.
• It assumes that there is a linear relationship between the input and
output
• Uses a best-fit line to make predictions
TYPES OF LINEAR REGRESSION
1. SIMPLE LINEAR REGRESSION

Models the relationship between exactly one


independent variable (X) and one dependent
variable (Y) using a straight line
2. MULTIPLE LINEAR REGRESSION

Models the relationship between two or more


independent variables (x1, x2,…) and a single
dependent variable (Y)
SIMPLE LINEAR REGRESSION
Uses only one independent variable (input) to
predict the dependent variable (output)

Equation:

a₀ = intercept
a₁ = slope of the line
y = dependent variable (target)
x = independent variable (input)
SIMPLE LINEAR REGRESSION
PROBLEM

Consider an example where the five


weeks’ sales data (in Thousands) is
given as shown in Table.

Apply linear regression to predict


the 7th and 12th week sales.
SIMPLE LINEAR REGRESSION
MULTIPLE LINEAR REGRESSION
Uses multiple independent variable (input) to predict the
dependent variable (output)
Multiple regression equation for 2 variable x1 & x2 is :

General form (n independent variables):


where:

The regression coefficient for Multiple regression is


calculated as:
MULTIPLE LINEAR REGRESSION
PROBLEM

Apply multiple regression for the


values given in Table where
weekly sales along with sales for
products x1 and x2 are provided.

Use matrix approach for finding


multiple regression.
EVALUATION METRICS FOR LINEAR
REGRESSION – REGRESSION METRICS
• Machine learning model cannot have 100% efficient otherwise the mode is
known as a biased model.

• Which further includes the concept of over-fitting and under-fitting.

• It is necessary to obtain the accuracy on training data, But it is also important to


get a genuine and approximate result on unseen data otherwise Model is of no
use.

• So to build and deploy a generalized model we require to Evaluate the model on


different metrics which helps us to better optimize the performance, fine-tune it,
and obtain a better result.
REGRESSION METRICS
Regression metrics are used to measure how well a regression model predicts
continuous numerical values.

Common Regression Metrics are of 4 types:

• MAE (Mean Absolute Error)


• MSE (Mean Squared Error)
• RMSE (Root Mean Squared Error)
• R² Score (Coefficient of Determination)
1. MEAN ABSOLUTE ERROR (MAE)

The Mean absolute error represents the average of the absolute difference between
the actual and predicted values in the dataset. It measures the average of the residuals
in the dataset. (Lower MAE = Better model performance.)
MEAN SQUARED ERROR (MSE)

Mean Squared Error represents the average of the squared difference between the
original and predicted values in the data set. It measures the variance of the residuals.
(Lower MSE = Better model performance.)
ROOT MEAN SQUARED ERROR
(RMSE)
• Square root of MSE
• Error is in the same unit as the target.
• Lower RMSE value is better.
R SQUARED (R )
2

Measures the proportion of variance in the dependent variable (target) explained by the
independent variable (input). Ranges from 0 to 1 (or 0 % to 100 %). (Closer to 1 is better)
For example:
• R² = 0 → Model does not explain the variation well.
• R² = 0.5 → Model explains about 50% of the variation.
• R² = 1 → Perfect prediction.
• Higher R² = Generally better model
Formula: Where:
= (Residual Sum of Squares): The sum of squared differences
between actual values and predicted values

= (Total Sum of Squares): The sum of squared differences


between actual values and the overall mean of the data

= Actual values

= Predicted values

= Mean of actual values


Classification
Models
LOGISTIC REGRESSION MODEL
• Supervised machine learning algorithm.
• Used primarily to solve classification problems by predicting the probability that an
instance belongs to a specific category. Despite having "regression" in its name, its
output is categorical rather than a continuous numerical value.
• Uses a sigmoid function to convert the output into a probability value between 0 and 1.
• The output of the model is a value between 0 and 1.
Equation:

where
NAÏVE BAYES CLASSIFIER
• Supervised machine learning algorithm.
• Based on Bayes’ Theorem.
• It assumes that all the features are independent of each other.
• It calculates the probability of each possible class and selects the class with the highest
probability.
DECISION TREES

• Supervised machine learning algorithm.


• It is used for both Classification and Regression Problems.
• It represents decisions in the form of a tree-like structure.
• It starts with a root node and divides the data based on feature values.
• Internal nodes represent conditions or decisions based on features.
• Branches represent the possible outcomes of those decisions.
• Leaf nodes represent the final prediction or output.
• For classification, splitting can be based on measures such as Entropy and Information
Gain.
DECISION TREES
Example:
DECISION TREES
To evaluate split in feature selection, we use two measures: Entropy and Information
Gain.

1. Entropy:
Entropy measures the impurity or uncertainty in a dataset.

Eg:
• If all the class labels are “Yes” , Or all the class labels are “No”,
then, Entropy = 0. i.e., Entropy = 0 → The data contains only one class. (Pure)

• If half of the class labels are “Yes” and half “No”,


ie., when equal no. of class labels present,
Entropy = 1 (Impure)
DECISION TREES

Formula:
DECISION TREES
2. Information Gain:
• Information Gain tells us how much uncertainty is reduced after splitting the
data.
• It helps the Decision Tree select the best feature for splitting.
• The feature with the highest Information Gain is selected for the split.

Formula:
ID3 – Iterative Dichotomiser 3
- Decision Tree Algorithm

• Uses Entropy and Information Gain to select the best feature.


• Chooses the feature with highest Information Gain.
• Multi- way splits possible.
• Used only for classification problems.
ID3 – Iterative Dichotomiser 3
Problem 1: - Decision Tree Algorithm
ID3 – Iterative Dichotomiser 3
- Decision Tree Algorithm
K – NEAREST NEIGHBOUR (KNN)

• Supervised machine learning algorithm.


• Used for classification and regression, but mostly used for the Classification problems.
• It predicts the output of a new data point based on its nearest data points.
• KNN is a distance-based algorithm.
• For classification → the majority class among the neighbours is selected.
• For regression → the average of the neighbours' values is used.
• K → Number of nearest neighbours considered.
K – NEAREST NEIGHBOUR (KNN)
SUPPORT VECTOR MACHINE (SVM)

• Supervised machine learning algorithm


• Used for both classification or regression problems. However, it is
mostly used in classification problems.
• In this algorithm, we perform classification by finding the hyperplane
that differentiate the two classes very well.
• The core idea of SVM is to find a maximum marginal hyperplane(MMH)
that best divides the dataset into classes.
SUPPORT VECTOR MACHINE (SVM)
SUPPORT VECTOR MACHINE (SVM)
Hyperplane:
A hyperplane is a decision boundary that separates different classes.
For 2D data, the hyperplane is a line.
For 3D data, the hyperplane is a plane.
SUPPORT VECTOR MACHINE (SVM)
Linear SVM:
• Used when the classes can be separated using a straight line or linear hyperplane.
• Finds the optimal hyperplane with maximum margin.
• Suitable for linearly separable data.

Non - Linear SVM:


• Used when data cannot be separated by a straight line.
• Uses a kernel function to handle complex data, that
transforms non linearly separable data to linearly separable data.
Common kernels:
o Linear Kernel
o Polynomial Kernel
o RBF (Gaussian) Kernel
o Sigmoid Kernel
CLASSIFICATION METRICS

Classification Metrics are used to evaluate the performance of a classification model.

Common Classification Metrics:


• Confusion Matrix
• Precision
• Recall
• F1-Score
• ROC Curve
• AUC

Purpose: To understand how well the model correctly classifies the data.
CLASSIFICATION METRICS

1. CONFUSION MATRIX:

A Confusion Matrix is a table used to compare the actual classes


with the predicted classes of a classification model.
CLASSIFICATION METRICS
• True Positive (TP): The model correctly predicted a positive
outcome. i.e., the actual outcome was positive.
• True Negative (TN): The model correctly predicted a negative
outcome i.e., the actual outcome was negative.
• False Positive (FP): The model incorrectly predicted a positive
outcome i.e., the actual outcome was negative. It is also known
as a Type I error.
• False Negative (FN): The model incorrectly predicted a negative
outcome i.e., the actual outcome was positive. It is also known
as a Type II error.
CLASSIFICATION METRICS
2. ACCURACY:
• Accuracy measures the overall correctness of the classification
model.
• It tells us the proportion of correct predictions made by the
model out of all predictions.
• Higher accuracy indicates better overall model performance.
CLASSIFICATION METRICS

3. PRECISION:

• Precision measures how many of the samples predicted as


positive are actually positive.
• High precision means fewer False Positives (FP).
CLASSIFICATION METRICS

4. RECALL:

• Recall measures how many of the actual positive samples are


correctly identified by the model.
• High recall means fewer False Negatives (FN).
CLASSIFICATION METRICS

5. F1 - SCORE:

• F1-Score combines Precision and Recall into a single metric.


• Provides a balance between Precision and Recall.
• Higher F1-Score indicates better performance.
CLASSIFICATION METRICS

6. ROC CURVE

• ROC (Receiver Operating Characteristic) Curve evaluates the performance


of a classification model at different classification thresholds.
• X-axis: False Positive Rate (FPR)

• Y-axis: True Positive Rate (TPR) (also called ‘Recall’ or ‘Sensitivity’)


CLASSIFICATION METRICS
CLASSIFICATION METRICS
7. AUC Curve:

AUC (Area Under the Curve) represents the area under the ROC
curve.
• AUC = 1.0 → Perfect classification
• AUC = 0.5 → Random guessing
• AUC < 0.5 → Worse than random performance
• Higher AUC indicates better ability of the model to distinguish
between classes.
• AUC is useful for comparing classification models..
CLASSIFICATION METRICS
Thank You

You might also like