Module-5-AI
Module-5-AI
MODULE – 5
1) Instance-Based Learning: INTRODUCTION
The learning in Machine learning can be either Generalized Learning (or) Memorized Learning.
Instance-based learning comes under the category of Memorized Learning and hence it is also
known as Lazy Learning.
In Generalized Learning, we use Training sets and store them, have labels to identify each features.
Whereas in Instance-Based learning, we don‟t store anything neither any labels to identify the
instances.
Since in Instance-Learning we don‟t store any information, we need to identify the instances as and
when they arrive.
Instance Based
Learning
Lazy Learners(NN) Nearest Radial Basis Function (RBF) Case Based Reasoning (CBR)
Neighbor method) Weighted methods
In instance-based learning, when we are given Large Set of Instances, and whenever each new
instances arrives, we will locally assign Target Function for each instances.
K-Nearest Neighbour is one of the simplest Machine Learning algorithms based on Supervised
Learning technique.
K-NN is a non-parametric algorithm, which means it does not make any assumption on
underlying data.
It is also called a lazy learner algorithm because it does not learn from the training set
immediately instead it stores the dataset and at the time of classification, it performs an action on
the dataset.
Dept. Of CSE in AIML Page 1 | 14
VVIT,B’lore
Artificial Intelligence BAD402
K-NN algorithm assumes the similarity between the new case/data and available cases and put the
new case into the category that is most similar to the available categories.
Example: Suppose, we have an image of a creature that looks similar to cat and dog, but we want to
know either it is a cat or dog. So for this identification, we can use the KNN algorithm, as it works
on a similarity measure. Our KNN model will find the similar features of the new data set to the cats
and dogs images and based on the most similar features it will put it in either cat or dog category.
The reason why we say KNN is a Lazy Learning algorithm is because it only tries to start the
process by memorizing and not by learning itself.
It classifies the new points based on a Similarity Measure known as Euclidean distance.
Suppose we have a new data point and we need to put it in the required category. Consider the
below image:
Firstly, we will choose the number of neighbors, so we will choose the k=5.
Next, we will calculate the Euclidean distance between the data points. The Euclidean distance is
the distance between two points. It can be calculated as:
By calculating the Euclidean distance we got the nearest neighbors, as three nearest neighbors in
category A and two nearest neighbors in category B. Consider the below image:
As we can see the 3 nearest neighbors are from category A, hence this new data point must belong
to category A.
The value of „k‟ must be chosen always as a ODD number, otherwise there will be a tie during the
classification.
Step-3: Take the K nearest neighbors as per the calculated Euclidean distance.
Step-4: Among these k neighbors, count the number of the data points in each category.
Step-5: Assign the new data points to that category for which the number of the neighbor is
Regression: is a statistical tool used to understand and quantify the relation between two or more
variables.
Linear Regression
For non-linearly separable data, we will use the Locally Weighted Regression(LWR).
The nearest neighbor approach can be thought of as approximating the target function, whereas
Locally weighted regression is a Generalization of this approach.
Locally Weighted Regression tries to overcome the problem faced in a Linear Regression method
by assigning weights to the training data.
LWR requires the entire data set every time you try to make a prediction.
It makes much more computationally expensive compared to the simple linear regression.
Assigning a weight is not a simple process, but we should use some algorithm or methods in
assigning the weight.
Kernel Smoothing is a method which is used to assign the weights to the training data.
Diagonal Matrix means, all the diagonal elements will have some values, whereas in other places it
will be Zero.
Example:
So, the above example is a non-linearly separable data. Hence we need to first convert this Non-Linearly
separable into a Linearly Separable data.
So, from here we need to calculate the radius „r‟, which is the distance from the center point till the star
that touched on the circle in this example.
This radius „r‟ is needed to use it for the functions used for Expanding and compressing as follows;
From the above 3 functions, we can use any ONE of the function.
In CBR, everything is considered as case, and based on previous cases we propose a solution.
For modeling CBR, we use CADET system (Case based Design Tool).
CADET has 75 predefined libraries and using these libraries we will be generating any new
situations/cases/solutions.
This is a model of a Water Tap in which we can turn the Pipe towards Left side for Hot water, and
turn right side for Cold water, and if we keep in the middle we get a mix of both cold and hot level
water.
Now, the requirement is, we need to construct another Tap which will control the Temperature &
Waterflow i.e either Hot or Cold water, but not both mixed level. So, for this we will take the help
of the already available system.
Reinforcement learning is used to solve the problems that are reward based.
The agent learns by trial and error and tries to get the maximum possible reward by
performing certain actions in the environment.
Dept. Of CSE in AIML Page 9 | 14
VVIT,B’lore
Artificial Intelligence BAD402
Environment – a physical world where an agent learns and decides the actions to be
performed
Reward – For each selected action by agent, the environment gives a reward. It’s
usually a scalar value and nothing but feedback from the environment
Instead of one input producing one output, the algorithm produces a variety of outputs and is
trained to select the right one based on certain variables.
It is a type of machine learning technique where a computer agent learns to perform a task
through repeated trial and error interactions with a dynamic environment.
7) Q Learning
The AI agent is not seeking to learn about an underlying mathematical model or probability
distribution.
Instead, the AI agent attempts to construct an optimal policy directly by interacting with
the environment.
The AI agent repeatedly tries to solve the problem using varied approaches, and
continuously updates its policy as it learns more and more about its environment.
A „Q’ value indicates the quality of a particular action „a‟ in a given state „s‟ [ Q(s , a) ]
For example, if we consider the movement in a Maze where there is a Starting point
and End point as shown below;
In this, once we start from the “Start”, and our destination is at “End”, in between the
movement we shouldn‟t fall on the “CLIFF”. The possible movements here can be any
of these based on each location that we visit, i.e UP, RIGHT, DOWN, LEFT.
A possible Q-Table based on each location in this Maze can be represented in a Q-Table as
shown below;
Temporal Differences (TDs) provide us with a method of calculating how much the Q-
value for the action taken in the previous state should be changed based on what the AI
agent has learned about the Q- values for the current state‟s actions. Previous Q-values are
therefore updated after each step.
The Bellman equation tells us what new value to use as the Q-value for the action taken in
the previous state.
- Relies on both the old Q-value for the action taken in the previous state and what
has been learned after moving to the next state.
- Includes a learning rate parameter (α) that defines how quickly Q-values are adjusted.
Inference Mode
Once the Q-learning model is fully trained, it can be used for inference.
In inference mode:
- Q-values are no longer updated.
- For any state, that action that the AI agent chooses to take is simply the action with
the largest Q-value.