DLL Module 1 Notes
DLL Module 1 Notes
data.
Deep learning mimics neural networks of the human brain, it enables computers to
autonomously uncover patterns and make informed decisions from vast amounts of unstructured
data.
Takes less time to train the model. Takes more time to train the model.
Model created by manually Automatically extracts features from data
extracted features (e.g., detecting objects in end-to-end learning process.
images).
Less complex and easier to More complex, often acts as a black box
interpret results. (difficult to interpret).
Can work on CPU or with low computing Requires high-performance computing,
power. typically GPU.
Learning Algorithms
The Task, T
1. Classification
2. Classification with missing inputs
3. Regression
4. Transcription
5. Machine translation
6. Structured output
7. Anomaly detection
8. Synthesis and sampling
9. Imputation of missing values
10. Denoising
11. Density estimation or probability mass function estimation
“A computer program is said to learn from experience (E) with respect to some class of
tasks (T) and performance measure (P), if its performance at tasks in T, as measured
by P, improves with experience E.”
Representation of a Task
A machine learning task is usually described in terms of how a system processes an
example. An example: is a single observation or data point from the dataset.
is represented as a vector of features: x=[x1,x2,x3,…,xn]∈Rn
where each xi represents one measured feature of the object or event.
Term Description
Task (T) Classify an image as “cat” or “dog”.
Example (x) One image represented as pixel values.
Feature Vector (x = [x_1, x_2, x_3, \dots, x_n]), where each (x_i) is a pixel intensity.
Learning Goal Learn a function ( f(x) \to \text{label} ) that correctly predicts the
image category.
[Link] Task
Classification is a type of supervised learning task in which a computer program learns to
assign input data to one of several predefined categories or classes. Mathematically, the task is
to learn a function:
Intuitive Explanation
The algorithm learns from labeled examples (inputs with known categories) to predict
the correct class for new, unseen inputs.
The program learns a mapping from input features to discrete output labels.
Term Description
Task (T) Identify the object in an image.
Input (x) Image represented as pixel brightness values.
Output (y) Category (e.g., “bottle”, “glass”, “cup”).
Goal Correctly recognize which kind of drink is in the image.
When some inputs are missing, the algorithm must conceptually handle many possible
input subsets.
Each missing-input combination corresponds to a different function.
If there are n input variables, there can be up to: different functions (one for every possible
subset of missing inputs). Clearly, learning so many separate functions is impractical.
iii. This approach allows the classifier to handle any missing subset of inputs
without retraining.
Marginalization
Marginalization = summing or integrating over the missing features to estimate their
effect. For example:
Here x2 is missing, so the model integrates over its possible values.
Deep Probabilistic Models
Modern solutions use deep learning architectures that model complex joint distributions
efficiently. Examples include:
Mathematically:
Domain Example
Insurance
Predict expected claim amount made by an insured person to set premiums.
Finance Predict future stock prices or market trends for algorithmic trading.
Real Estate Predict house prices based on features (location, area, rooms).
Health Estimate blood sugar levels or tumor size from medical data.
• Output Type: Continuous numeric value.
• Goal: Minimize prediction error (e.g., Mean Squared Error).
• Relation to Classification: Similar structure, but output is real-valued rather than discrete.
4. Transcription
Transcription involves converting unstructured input data (images, audio, etc.) into discrete
textual sequences. Mathematically
Domain Example
Convert images of text into machine-readable
Optical Character Recognition (OCR) characters.
5. Machine Translation
In machine translation, the input is a sequence of symbols (words) in one language,
and the system must generate a sequence in another language.
7. Anomaly Detection
Anomaly detection involves identifying unusual or abnormal data points that deviate from
expected patterns.
Applications: Credit Card Fraud Detection: A model learns the normal pattern of a user’s
transactions.
If a purchase occurs in an unusual location or amount, it flags it as fraudulent.
• Medical Diagnosis: Detecting rare symptoms that deviate from typical patient data.
• Network Security: Detecting irregular network traffic indicating cyberattacks.
Approach: Machine learning models estimate a probability distribution over
normal data. When a new observation has low probability, it is marked as
anomalous. (Chandola et al., 2009) provides a comprehensive survey.
Definition: In missing value imputation, the learning algorithm is given a feature vector
with one or more missing components xi.
The task is to predict the missing entries based on the observed ones. Example
Medical Data: A patient’s record may lack blood test results. The model can infer
the missing hemoglobin level based on age, weight, and other known medical parameters.
Sensor Networks: Some sensors may fail, so the system estimates the missing
readings from nearby sensors.
Mathematical Basis
If we know the joint probability distribution p(x), we can compute:
The task is to recover the clean signal x or estimate the conditional probability:
Example: Image Denoising: Removing Gaussian noise or motion blur from an image.
Audio Denoising: Filtering noise from voice recordings.
Approach: Denoising Autoencoders (DAE): Learn a mapping
The model learns robust features that help reconstruct clean data from noise.
Significance: Denoising improves model robustness and helps uncover the
underlying structure of data even when partially corrupted.
For example, when performing a transcription task, should we measure the accuracy of the
system at transcribing entire sequences, or should we use a more fine-grained performance
measure that gives partial credit for getting some elements of the sequence correct?
True Statement the cat sat“ System Output "the cat sat“ Acc : 100%
When performing a regression task, should we correct the system more if it frequently
makes medium-sized mistakes or if it rarely makes very large mistakes?
True Statement "the cat sat on the mat“ System Output "the cat sat in the mat"
Models with low capacity may struggle to fit the training set.
Models with high capacity can overfit by memorizing properties of the training set that do
not serve them well on the test set.
One way to control the capacity of a learning algorithm is by choosing its hypothesis
space, the set of functions that the learning algorithm is allowed to select as being the
solution.
For example, the linear regression algorithm has the set of all linear functions of its input
as its hypothesis space.
We can generalize linear regression to include polynomials, rather than just linear
functions, in its hypothesis space.
A polynomial of degree one gives us the linear regression model with which we are
already familiar, with prediction yˆ = b + wx.
Models with insufficient capacity are unable to solve complex tasks. Models with high
capacity can solve complex tasks, but when their capacity is higher than needed to solve the
present task they may overfit.
Fig. 5.2 shows this principle in action. We compare a linear, quadratic and degree-9
predictor attempting to fit a problem where the true underlying function is quadratic.
The linear function is unable to capture the curvature in the true underlying problem, so it
underfits.
The degree-9 predictor is capable of representing the correct function, but it is also capable
of representing infinitely many other functions that pass exactly through the training
points, because we have more parameters than training examples.
We have little chance of choosing a solution that generalizes well when so many wildly
different solutions exist.
In this example, the quadratic model is perfectly matched to the true structure of the task so
it generalizes well to new data. Figure 5.2: We fit three models to this example training set.
The training data was generated synthetically, by randomly sampling x values and
choosing y deterministically by evaluating a quadratic function.
(Left) A linear function fit to the data suffers from underfitting—it cannot capture the
curvature that is present in the data.
(Center) A quadratic function fit to the data generalizes well to unseen points. It does not
suffer from a significant amount of overfitting or underfitting.
(Right) A polynomial of degree 9 fit to the data suffers from overfitting. Here we used the
Moore-Penrose pseudoinverse to solve the underdetermined normal equations.
The solution passes through all of the training points exactly, but we have not been lucky
enough for it to extract the correct structure.
underlying function.
this area.
ng a model’s capacity by changing the number of
input features it has (and simultaneously adding new parameters associated with those
features).
behave differently. At the left end of the graph, training error and generalization error are
both high. This is the underfitting rule.
generalization error increases. Eventually, the size of this gap outweighs the decrease in
training error, and we enter the overfitting rule, where capacity is too large, above the
optimal capacity.
Regularization
The no free lunch theorem implies that we must design our machine learning algorithms to
perform well on a specific task.
We do so by building a set of preferences into the learning algorithm. When these
preferences are aligned with the learning problems we ask the algorithm to solve, it
performs better.
Regularization is a technique used in machine learning and deep learning to reduce
overfitting by discouraging the model from becoming too complex.
It does this by adding a penalty to the loss function, which limits how much the model can
rely on large weights or complicated structures.
In simple terms, regularization helps the model focus on the most important patterns in
the training data and ignore noise or random fluctuations, leading to better performance on
new, unseen data.
There are different types of regularization:
Regularization Feature
Name Effect on Weights Initial Weights Example
Type Selection
Result
Some weights
L1 Lasso Yes ([4.9,-0.4,0.3]) ([4.9, 0,
become exactly 0 0.3])
All weights shrink but ([3.7, -0.5,
L2 Ridge No ([5.2,-0.8,0.46])
stay nonzero 0.25])
models.
Completely ignore: Location, Tech stack, Company Salary, Tech stack, Work-life balance,
size, Leave policy, Onsite opportunities, Manager, Company reputation, Career growth,
Job title Hybrid/remote, Leave policy
* All are important
This is sparse decision making → EXACTLY what L2 = “Consider everything, but keep it
L1 does. balanced.”
You end up with TCS because IBM or Infosys because: They provide a
➢ Salary is high & Work-life balance good mix of salary, learning, stability,
culture, hybrid work, benefits
is excellent
The prefix 'hyper_' suggests that they are 'top-level' parameters that control the learning
process and the model parameters that result from it.
Term Meaning Vehicles Dataset Example
Weights (W) Importance given to features High weight to wheels, low weight to
background
Biases (b) Adjustment that helps Helps detect vehicle even if image
activation contrast low
Layers Stages of feature extraction Layer 1 = edges,
Layer 2 = wheels/windows
Hidden Neurons inside layers Each unit learns parts: wheel, door,
Units light
Learning Rate Speed of weight updates High LR → learns too fast;
Low LR → too slow
Batch Size Images processed per update Batch = 32 vehicle images at a time
Epochs Number of times dataset is seen 10 epochs = sees all vehicle images 10
times
These values are automatically learned. The bank does not set them manually.
Hyperparameters are external settings that control how the model learns, not what it
learns. These are fixed by humans before training begins.
🎯 Bank Example:
Before building a loan model, the bank decides:
i. Learning rate → How fast the model learns patterns
ii. Batch size → How many customer records processed at once
Ex: 32 customers per batch
iii. Number of layers → How many decision layers the model use
iv. Number of training epochs → How many times the model sees all data
Ex: 50 epochs
Category Examples
These values are not [Link] are chosen by the data scientist before training.
To solve this problem, we need a validation set of examples that the training algorithm does
not observe.
Earlier we discussed how a held-out test set, composed of examples coming from the same
distribution as the training set, can be used to estimate the generalization error of a learner,
after the learning process has completed.
It is important that the test examples are not used in any way to make choices
about the model, including its hyperparameters.
For this reason, no example from the test set can be used in the validation set. Therefore,
we always construct the validation set from the training data.
Specifically, we split the training data into two disjoint subsets.
One of these subsets is used to learn the parameters.
The other subset is our validation set, used to estimate the generalization error during or
after training, allowing for the hyperparameters to be updated accordingly.
The subset of data used to learn the parameters is still typically called the training
set, even though this may be confused with the larger pool of data used for the entire
training process.
The subset of data used to guide the selection of hyperparameters is called the validation
set.
Typically, one uses about 80% of the training data for training and 20% for validation.
Since the validation set is used to “train” the hyperparameters, the validation set error will
underestimate the generalization error, though typically by a smaller amount than the
training error.
After all hyperparameter optimization is complete, the generalization error may be
estimated using the test set.
Cross-Validation in ML
This process is repeated multiple times, each time using a different fold as the validation
set.
Finally, the results from each validation step are averaged to produce a more robust estimate
of the model’s performance.
Cross validation is an important step in the machine learning process and helps to ensure that
the model selected for deployment is robust and generalizes well to new data.
Cross-validation is a technique for evaluating ML models by training several ML models on
subsets of the available input data and evaluating them on the complementary subset of the
data. Use cross-validation to detect overfitting, ie, failing to generalize a pattern.
Why do we need cross-validation?
Cross Validation is commonly used in Machine Learning to compare different models and
select the most appropriate one for a specific problem. It is both easy to understand, easy to
implement, and less biased than other methods.
Purpose of cross validation in machine learning
The purpose of cross–validation is to test the ability of a machine learning model to predict
new data.
It is also used to flag problems like overfitting or selection bias and gives insights on how
the model will generalize to an independent dataset.
The main aim of ML/data science analysts is to reduce these errors in order to get ore
accurate results.
Aspect Bias Variance
Definition
Error due to overly Error due to sensitivity to training
simple assumptions data
Model Behavior Underfits the data Overfits the data
Model Complexity Too low (simple model) Too high (complex model)
Training Error High Very Low
Test Error High High
Reason Model cannot capture real Model memorizes noise in training
pattern data
Example Model Linear regression with 1 feature Deep neural network or 15-degree
polynomial
Outcome Misses patterns Fails to generalize
Goal in ML Reduce bias without increasing Reduce variance without increasing
variance too much bias too much
What is Bias?
In general, a machine learning model analyses the data, find patterns in it and make
predictions.
While training, the model learns these patterns in the dataset and applies them to test data
for prediction.
While making predictions, a difference occurs between prediction values made by the
model and actual values and expected values, and this difference is known as bias errors
or Errors due to bias.
It can be defined as an inability of machine learning algorithms such as
Linear Regression to capture the true relationship between the data points.
Each algorithm begins with some amount of bias because bias occurs from
assumptions in the model, which makes the target function simple to learn.
A model has either:
Low Bias: A low bias model will make fewer assumptions about the form of the target
function.
High Bias: A model with a high bias makes more assumptions, and the model becomes
unable to capture the important features of our dataset.
A high bias model also cannot perform well on new data.
Generally, a linear algorithm has a high bias, as it makes them learn fast.
The simpler the algorithm, the higher the bias it has likely to be introduced. Whereas a
nonlinear algorithm often has low bias.
Some examples of machine learning algorithms with low bias are Decision Trees,
kNearest Neighbours and Support Vector Machines.
At the same time, an algorithm with high bias is Linear Regression, Linear Discriminant
Analysis and Logistic Regression.
In simple words, variance tells that how much a random variable is different from its
expected value.
Ideally, a model should not vary too much from one training dataset to another, which
means the algorithm should be good in understanding the hidden mapping between inputs
and output variables.
Case Model Example Training Test Real-World
Behavior Assumption Error Error Result
“EV adoption Wrong predictions;
High Bias Too simple depends only on High High misses important
(underfits) petrol price.” factors
How much the predicted target values from models trained using different samples vary
from each other;
Noise: How much the sample target values differ from the true model.
Low variance means there is a small variation in the prediction of the target function with
changes in the training data set.
At the same time, High variance shows a large variation in the prediction of the target
function with changes in the training dataset.
A model that shows high variance learns a lot and perform well with the training dataset, and
does not generalize well with the unseen dataset.
As a result, such a model gives good results with the training dataset but shows high error rates
on the test dataset.
Since, with high variance, the model learns too much from the dataset, it leads to overfitting
of the model. A model with high variance has the below problems:
High-Bias, Low-Variance:
With High bias and low variance, predictions are consistent but inaccurate on average.
This case occurs when a model does not learn well with the training dataset or uses few
numbers of the parameter. It leads to underfitting problems in the model.
High-Bias, High-Variance:
With high bias and high variance, predictions are inconsistent and also inaccurate on
average.
Case Meaning Real-World Example Explanation
1. Low Bias, Low Accurate The archer understands wind,
Variance and A skilled archer hitting the distance, angle (model captures
consistent bullseye repeatedly real patterns) and performs
consistently (low variance).
2. High Bias, Low A thermostat always showing It is consistently off-targetasdue
room temperature 5°Ctohigh
Variance Consistently a systematic error (high bias), but
wrong very stable (low variance).
3. Low Bias, High She understands how to frame the
Variance Accurate on A talented photographer photo (low bias) but camera
average but using an unstable tripod shakes create large fluctuations
inconsistent (high variance).
4. High Bias, Inaccurate and A new learner throwing darts Misses target due to wrong
High Variance inconsistent randomly, far from the technique (high bias) and
bullseye produces scattered throws (high
variance).
There are four possible combinations of bias and variances, which are represented by the
below diagram
Maximum Likelihood Estimation
The EM algorithm is considered a latent variable model to find the local maximum
likelihood parameters of a statistical model, proposed by Arthur Dempster, Nan Laird, and
Donald Rubin in 1977.
The EM (Expectation-Maximization) algorithm is one of the most commonly
used terms in machine learning to obtain maximum likelihood estimates of variables that are
sometimes observable and sometimes not observable .
However, it is also applicable to unobserved data or sometimes called latent (hidden).
It has various real-world applications in statistics, including obtaining the mode of the
posterior marginal distribution of parameters in machine learning and data mining
applications.
Note: Posterior: Conditional probability distribution representing what parameters are likely
after observing the data object.
Likelihood: The probability of falling under a specific category or class. In most real-life
time applications of machine learning, it is found that several relevant learning features are
available, but very few of them are observable, and the rest are unobservable.
Example used: Estimating the number of customers from two types (regular and tourists)
in a coffee shop where we cannot directly see who is who.
Real-World Scenario
A coffee shop wants to estimate:
How many regular customers visit daily
How many tourists visit daily
But customers do not tell who they are → hidden/unobserved variable. They
only record purchase amount, which is observable
If the variables are observable, then it can predict the value using instances.
On the other hand, the variables which are latent (hidden) or directly not observable, for such
variables Expectation-Maximization (EM) algorithm plays a vital role to predict the value
with the condition that the general form of probability distribution governing those latent
variables is known to us.
Application:
A medical researcher is studying the relationship between a patient's age and whether
they have a particular disease (yes/no).
Using a dataset of patients, the researcher uses MLE to estimate the coefficients in a
logistic regression model that predicts the probability of disease based on age.
What is an EM algorithm?
A latent variable model consists of both observable and unobservable variables where
observable can be predicted while unobserved are inferred from the observed variable.
These unobservable variables are known as latent variables.
EM Algorithm
The EM algorithm is the combination of various unsupervised
ML algorithms, such as the k-means clustering algorithm
Being an iterative approach, it consists of two modes.
In the first mode, we estimate the missing or latent variables. Hence it is
referred to as the Expectation/estimation step (E-step).
Further, the other mode is used to optimize the parameters of the models so that it can
explain the data more clearly.
The second mode is known as the maximization-step or M-step
Expectation step (E - step): It involves the estimation (guess) of all missing values in the
dataset so that after completing this step, there should not be any missing value.
Maximization step (M - step): This step involves the use of estimated data in the E-step
Repeat E-step and M-step until the convergence of the values occurs.
The primary goal of the EM algorithm is to use the available observed data of the dataset to
estimate the missing data of the latent variables and then use that data to update the values of
the parameters in the M-step.
Steps in EM Algorithm
Initialization Step :1st Step: The very first step is to initialize the parameter
values. Further, the system is provided with incomplete observed data with the
assumption that data is obtained from a specific model.
Expectation Step 2nd Step: This step is known as Expectation or E-Step, which is used to
estimate or guess the values of the missing or incomplete data using the observed data.
Further, E-step primarily updates the variables.
Maximization Step 3rd Step: This step is known as Maximization or M-step, where we use
complete data obtained from the 2nd step to update the parameter values.
Further, Mstep primarily updates the hypothesis.
Convergence Step 4th step: The last step is to check if the values of latent variables are
converging or not. If it gets "yes", then stop the process; else, repeat the process from step 2
until the convergence occurs.
Applications of EM algorithm
The primary aim of the EM algorithm is to estimate the missing data in the latent
variables through observed data in datasets.
The EM algorithm or Latent Variable Model has a broad range of real-life applications
in machine learning.
These are as follows:
The EM algorithm is applicable in data clustering in machine learning.
It is often used in computer vision and NLP (Natural language processing).
It is used to estimate the value of the parameter in mixed models such as the Gaussian
Mixture Model and quantitative genetics.
It is also used in psychometrics for estimating item parameters and latent
abilities of item response theory models.
It is also applicable in the medical and healthcare industry, such as in image
reconstruction and structural engineering.
It is used to determine the Gaussian density of a function.
Explore how MLE is used in classification tasks, such as object recognition or sentiment
analysis, by deriving and implementing the MLE-based classifier
Maximum Likelihood Estimation (MLE) is a statistical method used to find the parameters of
a model that maximize the probability of observing the given data.
In the context of classification tasks, MLE is used to determine the optimal model parameters
that best fit the training data, allowing for accurate predictions on new, unseen data.
The MLE Process in Classification Model Selection: Choose a suitable probability
distribution for the data.
This choice often depends on the nature of the classification problem (e.g., Bernoulli
distribution for binary classification, multinomial distribution for multi-class classification).
Parameter Estimation: Define the model parameters. These parameters represent the
characteristics of the distribution that influence the classification decision.
Likelihood Function: Construct the likelihood function, which expresses the
probability of observing the given training data under the chosen model and parameters.
Maximization: Find the values of the model parameters that maximize the likelihood
function. This is typically done using optimization techniques like gradient ascent or
Newton-Raphson.
Classification: Once the optimal parameters are determined, the model can be used to
classify new data points by calculating their likelihood under the learned model and
assigning them to the class with the highest probability.
Expectation step (E - step): It involves the estimation (guess) of all missing values in the
dataset so that after completing this step, there should not be any missing value.
➢ Maximization step (M - step): This step involves the use of estimated data in
the E-step and updating the parameters
➢ Repeat E-step and M-step
until the convergence of the
values occurs.
➢ The primary goal of the EM
algorithm is to use the
available observed data of the
dataset to estimate the
missing data of the latent
variables and then use that
data to update the values of
the parameters in the M-step.
Steps in EM Algorithm
Initialization Step :1st Step: The very first step is to initialize the parameter values. Further,
the system is provided with incomplete observed data with the assumption that data is
obtained from a specific model
Expectation Step 2nd Step: This step is known as Expectation or E-Step, which is used to
estimate or guess the values of the missing or incomplete data using the observed data.
Further, E-step primarily updates the variables.
Maximization Step 3rd Step: This step is known as Maximization or M- step, where we
use complete data obtained from the 2nd step to update the parameter values. Further, Mstep
primarily updates the hypothesis.
Convergence Step 4th step: The last step is to check if the values of latent variables
are converging or not.
If it gets "yes", then stop the process; else, repeat the process from step 2 until the
convergence occurs.
Bayes' Theorem
Bayes' Theorem, named after 18th-century British mathematician Thomas Bayes, is a
mathematical formula for determining conditional probability.
Conditional probability is the likelihood of an outcome occurring based on a previous
outcome in similar circumstances.
The Bayes theorem is frequently referred to as the Bayes rule or Bayes Law.
One of the most well-known theories in machine learning, the Bayes theorem helps
determine the likelihood that one event will occur with unclear information while another
has already happened.
Bayes' theorem describes the probability of occurrence of an event related to any condition.
It is also considered for the case of conditional probability.
Bayes theorem is also known as the formula for the probability of “causes” Bayes'
Theorem: At its core, Bayesian statistics is built upon Bayes' theorem, which relates
conditional probabilities.
The theorem can be expressed as follows:
represents the probability of event A occurring given that event B has occurred. P(B | A)
is the probability of event B occurring given that event A has occurred.
P(A) and P(B) are the marginal probabilities of events A and B, respectively.
Bayesian Inference:
Bayesian inference involves using Bayes' theorem to estimate or update the parameters of a
statistical model based on observed data.
This process typically includes:
Choosing a prior distribution that reflects your initial beliefs.
Defining a likelihood function that describes the data-generation process.