AI Module 2 Notes
AI Module 2 Notes
MODULE 2
CHAPTER:Artificial Intelligence Technologies
Techniques in AI
Artificial Intelligence (AI) means making computers or machines think and act like
humans.
How does it work?
It works by using a lot of data (information), fast computers, and smart programs
(algorithms). These programs learn from the data automatically — they look for
patterns and make decisions or predictions on their own.
When we build AI, we’re basically trying to copy human intelligence — like how we
see, speak, learn, and make choices — and make a machine do the same.
AI is a big area that includes many smaller parts (called sub-domains), All these areas
use data and algorithms to help the system learn and improve automatically.
[Link] networks
Neural networks are a way for computers to learn and make decisions like the human
brain.
In our brain, we have neurons (nerve cells) that send signals to each other. Similarly,
in a neural network, there are artificial neurons (called nodes) that pass information to
one another.
Each node receives some input (data), does some calculations, and sends the result to
the next node. The computer repeats this process many times to learn patterns and
understand the data better.
A neural network usually has three main parts:
Input layer – where the data enters the network (for example, an image or a number).
Hidden layer(s) – where the actual learning happens. The computer adjusts values
called weights and biases and thresholds to improve accuracy each time it processes
the data.
Output layer – This layer gives the final result or prediction after processing.
(for example, identifying an image as a cat or dog).
[Link] Learning
Machine Learning is a part of computer science that helps computers learn from data
on their own — without humans giving step-by-step instructions.
Instead of telling the computer exactly what to do, we give it lots of examples (data).
The computer then studies that data, finds patterns, and learns how to make decisions
or predictions.
Machine Learning (ML) is a subfield of Artificial Intelligence (AI) that enables
computers to analyze data, identify patterns, and make decisions with minimal human
intervention.
Instead of being explicitly programmed, ML systems learn from experience by
processing large datasets and recognizing trends or relationships within the data.
ML algorithms continuously improve their performance by comparing predicted
results with actual outcomes and adjusting their models accordingly.
The learning process involves training the system on historical data until it achieves a
desired level of accuracy.
Once trained, the machine can make predictions or decisions on new, unseen data
with improved precision.
This automation enhances efficiency, reduces human effort, and supports data-driven
decision-making across various domains.
1. Neural Networks with Layers: DL uses deep neural networks, which are neural
networks with multiple hidden layers. Each hidden layer processes the output from
the previous layer, allowing the system to learn complex patterns in large datasets.
Example: In image recognition, the first layer might detect edges, the next layer might
recognize shapes, and further layers might identify objects.
2. Forward Propagation: Data moves from the input layer, through hidden layers, to
the output layer. This step, called forward propagation, produces the model’s
prediction.
Example: In an image recognition task, forward propagation will take raw pixel
data, process it layer by layer, and finally output a classification like "cat" or "dog."
3. Backward Propagation: If the output is not accurate, the system calculates the error,
updates the weights assigned to each neuron, and sends the adjustments back through
the network. This process, called backward propagation, trains the model to improve
accuracy.
Example: If the model misclassifies an image, backward propagation helps the model
adjust its calculations to avoid the same mistake next time.
4. Training the Model: The model learns from both the forward and backward
propagation processes by adjusting weights, improving its accuracy with every
iteration.
Example: Over time, with enough data, the model gets better at recognizing
images or predicting outcomes.
Learning Capabilities: Deep learning can work with both labeled (supervised learning)
and unlabeled (unsupervised learning) data, making it highly versatile.
Applications: Image Recognition Speech Recognition, Natural Language Processing
(NLP)
Applications of Computer Vision: Computer vision techniques are used today for
facial recognition that helps in surveillance and security systems, autonomous
vehicles, retail stores for tracking inventory and customers, in medicine for
diagnosing diseases, in financial Institutions to prevent fraud, and so on.
GPUs are designed to handle these large volumes of data more efficiently than
traditional CPUs, making them ideal for tasks like:
Parallel Processing: GPUs can process many operations at once, speeding up the
training of models.
Faster Training of Neural Networks: They help process the data through multiple
layers in deep learning, making models train faster.
Example: In deep learning, GPUs are used to train models for tasks like image
recognition or
speech recognition, where data is analyzed and patterns are learned across millions of
inputs.
2. Internet of Things : The Internet of Things (IoT) refers to a network of connected
devices that generate massive amounts of data. These devices can range from
smartphones and wearables to home appliances and industrial sensors. However, this
data often remains unprocessed or under-analyzed.
AI and advanced algorithms help in automating the analysis of IoT data, extracting
useful insights and making sense of the vast amounts of information. Here's how AI
plays a role:
Data Analysis at Scale: AI can analyze data from millions of connected devices
quickly and efficiently.
Predicting Rare Events: AI models can identify patterns and predict rare events (like
equipment failure in manufacturing) that could otherwise be missed.
Understanding Complex Systems: AI helps make sense of complex systems (e.g.,
smart cities, healthcare systems) by analyzing data from various sources.
Tom M Mitchell:
“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.”
[Link] €
[Link] (P).
[Link] Algorithms
[Link] Algorithms
[Link] Algorithms
A classification algorithm classifies data into a particular [Link]
techniques predict discrete categories(Discrete (fixed categories) — not numbers that
vary continuously.).
The algorithm learns from examples and then classifies new data into one of the
known categories.
The output will be based on what the model has learned in training phase.
Example:
Predicting if a fruit is Apple or Mango
Predicting if an email is Spam or Not Spam
Predicting if a tumour is Cancerous or non-Cancerous
Classification algorithms are best used if data can be tagged,categorized, or separated into specific
groups or classes.
Example: If you have a dataset of fruits with labels like apple and banana, the
algorithm learns the features (color, size, shape) of each fruit and associates them with
the correct label(category)
Prediction:
After learning from the data, the model can predict the category (class) for new,
unseen data based on the patterns it has learned.
Example: When given a new fruit (e.g., color = red, shape = round), the model
predicts that it’s an apple.
[Link] Algorithms
A Regression Algorithm is used in machine learning to predict a real value (a
continuous number) based on the data it has learned from. Unlike classification
algorithms, which predict discrete categories, regression algorithms predict
continuous values.
For example, the cost of a product, the value of a stock, changes in temperature or
fluctuations in power demand.
For example, if we give an image of mango and anorange, then initially, the machine
has no idea about how a mango looks and how the orange looks.
It just looks at the features:color,shape,size,texture.
Then it notices patterns like:
“These round and orange-colored fruits look similar.”
“These oval and yellow ones look similar.”
So it groups them into two clusters:
Group 1 → Round, orange fruits
Group 2 → Oval, yellow fruits
What an unsupervised machine learning cannot do is specifying labels to the clusters
The machine doesn’t know the names (it doesn’t know “this is mango” or “this is
orange”).
It just groups them based on similarity.
1. Clustering
Clustering is a type of unsupervised learning where the computer automatically
groups/clusters similar data points together — without being told what the groups are.
This technique helps to discover hidden patterns or inherent groupings(already
existing inside) in the data, which might not be obvious at first glance.x`
Clustering finds groups, but not names for those groups.
You, the human or data scientist, look at each cluster afterward and decide what it
represents.
Think of clustering as the process of organizing things that are alike into the same
group.
For example:
All red, round fruits (apples) go in one cluster
All yellow, oval fruits (mangoes) go in another cluster
Even though the machine doesn’t know the names “apple” or “mango,” it groups
them based on similar features like color and shape.
[Link] analysis
Association analysis is an unsupervised learning technique used to find relationships
or connections between items in large datasets.
It discovers rules or patterns like:
“If one thing happens, another thing often happens too.”
In other words, it helps find which items tend to occur together.
How Association Analysis Works:
Finding Relationships:
Association analysis tries to find patterns that describe how different items or actions
are linked together. Example: If customers frequently buy bread, they might also buy
butter. The analysis finds that these two products are often purchased together.
Creating Association Rules:
The main goal is to create association rules in the form of: "If X happens, then Y
happens".
These rules help businesses understand which items tend to be bought together.
Example: "If a customer buys a laptop (X), then they are likely to buy a mouse (Y)."
This rule can be used to recommend related products to customers.
Simple Meaning
It’s like the machine is saying:
“People who buy this, often buy that too!”
So, it helps us understand how items are related in the data.
Example: Shopping Store
Many customers who buy bread also buy butter.
The machine finds this pattern automatically.
3. Dimensionality reduction
Dimensionality Reduction is a technique used to simplify a dataset by reducing the
number of features (variables) without losing important information. This is
especially useful when you have datasets with a large number of features, often in the
millions, making it difficult to process and analyze the data effectively.
When we collect data, sometimes each data item has many features (variables).
For example, if you have data about people:
If you have too many features (sometimes thousands or even millions), it becomes:
Hard for the computer to process
Slower to train a model
Difficult to visualize or understand
So, Dimensionality Reduction helps by reducing the number of features, while still
keeping the important information.
Why is Dimensionality Reduction Important?
Simplifies Data:
When datasets have too many features (variables), it can be overwhelming and
computationally expensive to work with them.
Dimensionality reduction reduces the number of features, making the dataset more
manageable.
Reduces Complexity:
Fewer features make models easier to train, faster to process, and often lead to better
performance. Reducing features also helps to avoid problems like overfitting, where a
model is too complex and doesn’t generalize well to new data.
Improves Visualization:
With too many features, it's hard to visualize the data. Dimensionality reduction
makes it easier to visualize the dataset in 2D or 3D.
4. Outlier Detection
Outlier detection, also known as anomaly detection, is a technique used to find rare or
unusual events in a dataset that do not follow the normal pattern.
These events or observations are called outliers and can indicate important issues like
fraud, errors, or new trends.
An outlier (or anomaly) is something that doesn’t fit with the rest of the data — it’s
rare or unusual.
Suppose you have the following data of students’ exam marks:
75, 80, 82, 78, 79, 5, 81, 77
Here, the mark 5 is very different from the rest — that’s an outlier.
The machine can be trained to detect such unusual values automatically.
How Outlier Detection Works:
[Link] Anomalies:
Outlier detection identifies data points that differ significantly from the rest of the
data.
Example: In credit card transactions, a sudden large withdrawal made in an unusual
location could be
flagged as an anomaly (possible fraud).
[Link] (KNN):
Semi-Supervised Learning
Semi-supervised learning algorithms is a mix of supervised and unsupervised learning
[Link] they use both labelled and unlabelled data for training.
It uses:
A small amount of labelled data (data with correct answers given)
A large amount of unlabelled data (data with no answers)
Simple Meaning:
Imagine you are a teacher training a student:
The student uses what they learned from the few solved ones to guess
answers for the rest.
Semi-supervised learning techniques can be applied using any of the two approaches
given below.
Approach 1:
Start with a small labelled dataset (Supervised step) → train a basic model.
Then, use this model to predict labels for the large unlabelled dataset (Unsupervised
step).
Repeat the process multiple times — the model becomes more accurate each time.
Example:
You label 100 fruit photos manually → the model learns.
It then labels 1,000 unlabelled photos automatically → retrains on them → becomes
smarter.
Approach 2:
Start with Unsupervised Learning (Clustering) → group similar unlabelled data.
Then assign labels to each cluster and train the model using that information.
Example:
Group all similar fruits first (apples together, bananas together).
Then label each group (“This cluster = apples”).
Use this new labelled data to train the model.
Reinforcement Learning needs lots of experiences (data) to learn, so it’s mainly used
in simulated environments (like games or robotics) where the agent can safely try
many times and learn the best possible way (path or behaviour) to reach its goal.
But in the real world, it’s not always possible or safe to try many times.
For example:
A self-driving car cannot keep crashing in real life just to learn driving!
So, it needs a simulated environment (a computer-generated world) to practice safely.
Reinforcement learning is different from supervised learning.
In supervised learning, the training data has labels, so the
model is trained with the correct answer but in case of RL, the reinforcement agent
decides what to do to perform the given task.
In the absence of a training dataset, it is bound to learn
from its own experience.
Example:
Imagine a robot inside a game:
It wants to reach a diamond (reward) ô
But there are fires (hurdles or punishments) ô in the path
The robot tries different paths:
If it moves closer to the diamond → ✅ it gets a reward,If it touches
fire → ❌ it gets a penalty
Each right step earns a reward and every wrong
step will subtract the reward of the robot. The total reward is
calculated when it reaches the final reward that is the diamond
After many tries, the robot learns which path gives maximum
reward (best result) and avoids penalties (wrong steps).
Example: In a game scenario, the agent might be a robot and the environment is the
game world.
Rewards and Penalties:
Rewards are given for performing correct actions, while penalties are given for
incorrect actions. The agent’s goal is to maximize its total reward over time by
learning from experience.
Example: If a robot picks the right path in the game (avoiding fire), it earns a reward
(like a diamond). If it chooses the wrong path (touches fire), it loses some reward.
Trial and Error:
The agent starts with no knowledge and learns by trying different actions, observing
the results, and adjusting its strategy.
Over time, the agent learns which actions lead to the highest rewards and which
actions lead to penalties.
Types of Reinforcement
In Reinforcement Learning (RL), reinforcement refers to the process of giving
feedback to an agent based on its actions to encourage or discourage certain behaviors.
1. Positive Reinforcement-
Positive reinforcement occurs when an action taken by the agent produces a positive
outcome or reward, which increases the likelihood of that action being repeated in the
future. This type of reinforcement strengthens the desired behaviour and helps the
agent learn faster. It motivates the agent to continue performing actions that lead to
beneficial results.
Example : Consider a robot learning to navigate a maze. Each time it moves closer to
the exit, it receives a reward of +10 points. This reward acts as positive reinforcement,
encouraging the robot to take similar paths in the future. Over time, the robot learns
the optimal route that gives the maximum cumulative reward.
Meaning:
When you reward a good action or behaviour so that it happens more often in
the future.
✅ In simple words:
If you do something right and get a reward, you’ll want to do it again.
Example 1 – Human life:
2. Negative Reinforcement
Negative reinforcement occurs when a certain behaviour is strengthened by removing
or avoiding a negative condition. In this case, the agent learns to perform actions that
Example: In the same maze problem, if the robot hits a wall, it receives a penalty of
−5 points. When it changes direction to avoid the wall and the penalty stops, this
avoidance behaviour is negatively reinforced. The robot learns that moving away
from walls helps it avoid losing points, so it continues to do so in future attempts.
Negative reinforcement helps the agent refine its actions by learning which paths or
strategies reduce negative feedback and lead to better overall performance.
Meaning:
When you remove or avoid something unpleasant to
encourage the behaviour.
✅ In simple words:
If you do something right and it helps you avoid a bad
situation, you’ll do it more often.
[Link] can be used to create training systems that provide custom instruction and
materials according to the requirement of students.
RL can design personalized learning platforms that adjust lessons or exercises based
on how each student performs giving easier or harder questions as needed.
After building the regression model, evaluate its accuracy by measuring how well it
predicts new data.
Summary:
Regression Analysis helps predict continuous values (e.g., price, salary) based on the
relationship between dependent and independent variables.
Linear Regression is the most common technique, but multiple regression, non-linear
regression, and other techniques are used for more complex tasks.
Applications include cost predictions, profit calculations, and sales forecasting.
For example:
R² tells how much of the change in marks is because of the change in study hours.
If R² = 1 (or 100%), the model predicts perfectly — all data points lie exactly on the
regression line.
R² is between 0 and 1:It means the model partially explains the relationship between
the independent variable (X) and the dependent variable (Y).
Why?
Because when you add more x variables, R² always increases — even if those variables are not useful.
Example
Suppose you are predicting house price (y) using:
x₁ = area
x₂ = number of rooms
x₃ = color of the door (not important)
If you add x₃ (color of door),
R² will increase slightly — even though that variable is useless.
Adjusted R² will decrease — because it recognizes that x₃doesn’t really help.
In short:
R² tells you how well your model fits.
Adjusted R² tells you how well your model fits — after removing the effect of
unnecessary variables.
✅ (a) Adjusted R²
Evaluation Methods :
1. Train-Test Split
Dividing your dataset into two parts —
one part to train the model, and
another part to test how well it performs.
Why we do it:
We want to check whether our model can predict new, unseen data — not just
memorize the data it was trained on.
So we keep some data hidden (test data) and check the model’s performance later.
Typical split:
Most commonly:
Training set: 70–80% of the data
Testing set: 20–30% of the data
But if we split only once, the result may depend on how we split (some splits might be
“lucky” or “unlucky”).
That’s where K-Fold Cross-Validation helps.
2.k-fold cross-validation
It is a technique to evaluate a model more reliably by dividing the data into K equal
parts (folds).
Process:
Step 1: Randomly split the data set into k-subsets (or k-fold). For example, to generate
5 subsets, value of k = 5.
Step 2: Reserve one subset and call it as test data. Use rest of subsets to the train the
model.
Step 3: Test the performance of the model using the test data set and record the
prediction error.
Step 4: Repeat the above steps until each of the k subsets have been used as the test
set.
Step 5: Calculate the average of the k recorded errors. This is also known as cross-
validation error. Finally, the best model is the one that has the lowest cross-validation
error, RMSE.
Types of Regression
Regression analysis involves different types of models, each suited for specific types
of data and relationships between variables.
1. Linear Regression
2. Logistic regression
3. Ridge regression
4. Lasso (Least Absolute Shrinkage Selector Operator) regression
5. Polynomial regression
6. Stepwise regression
7. ElasticNet regression
1. Linear Regression
NOTE
The coefficient 10 means:
For every 1 additional hour of study, marks increase by 10.
The intercept (20) means:
The intercept (20) means:
Even if the student studies 0 hours, the predicted marks = 20.
(It’s the base or starting value when X = 0.)
The coefficient (10) shows the strength of the relationship — it’s the number that connects X
(hours) to Y (marks).
It tells how much Y changes when X changes.
2. Logistic Regression
3. Ridge Regression
your model is overfitting (performing well on training data but poorly on test data).
Lasso Regression is another type of regularized linear regression — just like Ridge —
but with a small twist.
Both Ridge and Lasso add a penalty to prevent overfitting.
However, Lasso can actually make some coefficients exactly zero, which means it can
remove irrelevant variables from the model.
So the name itself means:
[Link] Regression:
NOTE:
6. Stepwise Regression:
Builds the regression model by adding or removing variables step by step based on
performance.
Stepwise Regression is a method of selecting the most important independent
variables (features) for building the best regression model.
In simple words:
Instead of using all the predictors (X₁, X₂, X₃, …), stepwise regression automatically
chooses which ones to keep and which ones to remove — step by step.
Approaches:
Forward Selection: Starts with no variables and adds them one at a time.
Backward Elimination: Starts with all variables and removes them step by step.
Bidirectional Elimination: Combines both approaches.
Example: Selecting the most significant predictors in a dataset for predicting sales
growth
Classification Techniques
Classification is a type of machine learning task where the goal is to predict which
category or class an observation belongs to.
The model is trained using labeled data, where each input is already tagged with the
correct class or category. Based on this, the model learns the patterns and uses them to
predict the class of new, unseen data
The classification model takes input data (features) and assigns it to one of the
predetermined categories.
Example: In an email classification task, the model predicts whether an email is spam
or not spam based on the features (like subject, sender, content, etc.).
Clustering Techniques
Clustering is a set of unsupervised learning techniques used in Machine Learning to
divide or partition a dataset into a number of smaller groups, called clusters.
The purpose of clustering is to ensure that data objects within the same cluster are
similar to each other, while objects belonging to different clusters are dissimilar.
Meaningful clusters help us learn something new or insightful about data. Clustering
method enhances domain knowledge by revealing previously unknown relationships
among data objects.
Example (Healthcare):
Doctors can group patients based on how their bodies respond to a particular medicine.
Cluster 1: Patients who got cured fast.
Cluster 2: Patients who needed longer treatment.
Cluster 3: Patients who didn’t respond well.
This helps doctors to understand that one medicine doesn’t work the same way for
everyone.
On the other hand, useful clusters are those that serve as an intermediate step in a data
analysis process.
Example (Business):
A company can group customers based on buying habits:
Cluster 1: Regular buyers
Cluster 2: Occasional buyers
Cluster 3: One-time buyers
Then, they can send special offers to regular buyers and discount coupons to
occasional ones. This helps them target ads effectively.
1. Partitional clustering
[Link] Clustering
Instead of just dividing data into a fixed number of groups directly (like k-means),
it shows how clusters are formed step by step — either by merging or splitting.
Two Types of Hierarchical Clustering
[Link] (Bottom-Up approach)
Start with each data point as its own cluster.
Then merge the two clusters that are most similar (closest).
Keep merging until everything becomes one single big cluster.
Example:
Let’s say you have 4 points: A, B, C, D
Start → each is alone: {A}, {B}, {C}, {D}
Merge the two closest → {A,B}, {C}, {D}
Next closest → {A,B,C}, {D}
Finally → {A,B,C,D}
Advantages Limitations
1 Shows relationships at a finer level 1 Computationally expensive
Hierarchical clustering doesn’t just form clusters —
it shows how each data point is related to others. For large datasets, it takes a lot of time and memory.
The dendrogram (tree) helps you see which points Because it has to calculate distances between all pairs of
are closer or farther. points many times.
So, you can understand data structure in detail, not So it’s slower than simpler methods like K-Means.
just the final groups. Example:
Example: If you have 10,000 data points → the algorithm has to
If you cluster students based on marks — compare millions of pairs!
you can see which students are most similar, which [Link] to noise and outliers
small groups form first, and how they later merge
into bigger groups. A few unusual(outliers) or incorrect data points(noise) can
2 Easy to interpret disturb the whole tree structure.
The tree (dendrogram) makes results visual and Once an incorrect merge/split happens early, it can’t be
simple to understand. corrected later.
So accuracy decreases if the data is messy or contains
You can literally see how clusters were formed or noise.
split.
3. Density-Based Clustering
Note :
In data science or clustering, density means how closely the data points are packed
together in a region. If many data points lie close to each other, that area is said to have
high density.
If very few points are present and they’re far apart, that area has low density.
In contrast to other clustering categories, density-based approach does not require the
user to specify the number of clusters. It uses a distance-based parameter that acts as a
threshold. The threshold value helps the algorithm to determine how close points must
be to be considered a cluster member.
Popular examples of density based Algorithms are :
Density-Based Spatial Clustering of Applications with Noise (or DBSCAN)
Ordering Points To Identify the Clustering Structure (or OPTICS)
Imagine stars in the sky ô
Where stars are close together, you can call that a cluster
(galaxy).
Where stars are spread far apart, that’s empty space (low
density).
K-Means Clustering
K-Means is a clustering algorithm that divides a dataset into K groups (clusters) based
on the similarity between data points.
It is called unsupervised learning because it works without labels — it finds patterns
or groups on its own.
Data points that are similar are grouped into the same cluster.
Data points that are different are placed in different clusters.
EXAMPLE 2
2. Image Segmentation
3. Recommendation Systems
4. Document Clustering
1. Inertia
Inertia indicates how far the points within a cluster are.
Inertia checks how close the points inside a cluster are (compactness),
It measures how tightly grouped the points are within each cluster.
It tells us if points inside a cluster are close to the cluster center (centroid) or not.
When we calculate Inertia, we deal with many clusters, not just one.
Step-by-step
First sum of distances of all the points within a cluster from the centroid of that cluster
is calculated.
Once inertia is calculated for all the clusters, the final value of inertia is obtained by
adding all these values.
The final value that gives the distance within the clusters is known as intra-cluster
distance. So, inertia gives us the sum of intra-cluster distances.
The inertial value ensures that the first property of clusters is satisfied.
Low Inertia → Points are close to the center → Clusters are compact → ✅ Good
High Inertia → Points are far away → Clusters are spread out → ❌ Poor
Goal: We want inertia to be as small as possible.
Simple Example:
Suppose we cluster students by their marks:
In Cluster 1, all marks are between 90–95 (close together) → small distance → low
inertia ✅
In Cluster 2, marks are between 60–90 (spread out) → large distance → high inertia
❌
So, the first cluster is better.
2. Dunn Index
High Dunn Index → Clusters are well separated and compact → ✅ Good
Low Dunn Index → Clusters overlap or are spread out → ❌ Poor
Goal: We want Dunn Index to be as high as possible.
The Dunn Index ensures that the second property of clusters is satisfied — clusters
should be far apart from each other.
******************************* END************************************