Artificial Intelligence and Machine Learning
Artificial Intelligence and Machine Learning
COMPUTER DEPARTMENT
6th SEMESTER
LEARNING
(03606387)
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
UNIT 1: Basics of AI
10. List out Production characteristics for State Space Search. (2M)
11. List out Production characteristics for Heuristic Search Techniques. (2M)
PIET - DS (CE) 2
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
3. List out Production Systems characteristics for State Space Search. (3M)
PIET - DS (CE) 3
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
2. What Are the Three Stages of Building a Model in Machine Learning? (3M)
3. What Are the Differences Between Machine Learning and Human Learning?(3M)
4. Explain K-means.(4M)
PIET - DS (CE) 4
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
2 MARKS QUESTIONS
PIET - DS (CE) 5
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
10. List out Production characteristics for State Space Search. (2M)
Implicity
Modifiability
Modularity
knowledge-intensive
11. List out Production characteristics for Heuristic Search Techniques. (2M)
Heuristics are knowledge about the domain, which help search and reasoning in its
domain.
Heuristic search incorporates domain knowledge to improve efficiency over blind
search.
A heuristic is a function that, when applied to a state, returns the value as estimated
merit of state, with respect to the goal.
• Heuristics might (for reasons) underestimate or overestimate the merit of a state
with respect to the goal.
• Heuristics that underestimate are desirable and called admissibly.
The heuristic evaluation function estimates the likelihood of a given state leading to the
goal state.
PIET - DS (CE) 6
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Based On Capabilities:-
• As systems with general AI are still under research, and it will take lots of efforts and
time to develop such systems.
Based On Functionality:-
1. Reactive Machines:-
Purely reactive machines are the most basic types of artificial intelligence.
Such AI system do not store memories or past experiences for future actions.
These machines only focus on current scenarios and react on it as per possible best
action.
IBM’s deep Blue System, Google’s etc. is an example of reactive machines.
2. Limited Memory:-
Limited memory machines can store data for a short period of time.
These machines can use stored data for a limited time period only.
Example of limited memory is self-driving cars are the best example.
3. Theory of Mind:-
Theory of mind AI should understand the human emotions people, beliefs and be
able to interact socially like humans.
This type of AI machines are still not developed but researchers are making lots of
efforts and improvement for developing such AI machines.
4. Self-Awareness:-
This type of AI is the future of artificial intelligence.
This type of machine have their own consciousness, sentiments and self-awareness.
This type of machine will be smarter than human mind.
Self-awareness AI does not exist in reality still and it is a hypothetical concept.
PIET - DS (CE) 8
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
The machines based on algorithms are trained on the best human knowledge and
experience with knowledge based on specific domains. The existing knowledge base can
be updated once new queries and solutions arise. The most common application to be
Robo-advisors or chatbots which can be used in a forward customer inquiry that can help
human in everything.
In this stage, the advanced systems can develop mastery in particular domains. Due to the
capability to store and process a wide volume of information to make decisions the
capabilities of these machines can be more than humans. Cancer diagnosis is one of the
applications and Google Deepmind's system that defeated 18 times world go champion Lee
Sadol proved the domain-specific expertise.
This machine algorithm has a concept of intellect, intentions, knowledge, and their own
logic. They have the capacity to reason, interact and, deal with other machines and humans
too. Such algorithms will be in the commercial arena in some years.
This is the main objective of many scientists working in the field of AI- to develop a
machine with intelligence like humans. The artificial general intelligence or self-aware
systems are not in application to date but not many years left to discover this avenue. This
is the stage represented in many sci-fiction movies that machines are leading humans in
intelligence.
This stage is one notch of the Artificial General Intelligence, the algorithms will be capable
of defeating smartest of the humans in all the domains. This stage can be the real solution
to the problems that are still complex for the human mind like poverty, hunger, and climate
change. This will be the stage where machines made by humans will outsmart humans too.
PIET - DS (CE) 9
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
The development path led by ASI will lead us to the point in time where the capabilities of
humans will see the tremendous extension. With the help of this ASI, technology humans
would be able to connect the minds of each other and be like the human internet. The
technology would be much like an imaginary life where ideas, and thoughts could be shared
by just one flick of mind. Humans would be capable of connecting with other forms of life
like animals, plants, and other natural activities. While some argue that humans will never
reach such levels and some say that it is feasible and with this exponential growth rate
would be achieved somewhere in 2045.
PIET - DS (CE) 1
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Every technology has some disadvantages, and the same goes for Artificial intelligence.
Being so advantageous technology still, it has some disadvantages which we need to keep
in our mind while creating an AI system. Following are the disadvantages of AI:
High Cost: The hardware and software requirement of AI is very costly as it requires lots
of maintenance to meet current world requirements. Can't think out of the box: Even we
are making smarter machines with AI, but still they cannot work out of the box, as the robot
will only do that work for which they are trained, or programmed.
No feelings and emotions: AI machines can be an outstanding performer, but still it does
not have the feeling so it cannot make any kind of emotional attachment with human, and
may sometime be harmful for users if the proper care is not taken.
Increase dependency on machines: With the increment of technology, people are getting
more dependent on devices and hence they are losing their mental capabilities.
No Original Creativity: As humans are so creative and can imagine some new ideas but
still AI machines cannot beat this power of human intelligence and cannot be creative and
imaginative.
PIET - DS (CE) 1
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
State-space search is used to locate a goal state with the desired feature.
In artificial intelligence, a process known as state space search is used to explore all
potential configurations or states of an instance until one with the necessary feature is
found.
A state is a time snapshot representing some aspect of the problem. It is common to practise
modelling a problem as a state space or a collection of possible states to understand it better.
If an operation can change one state into another, then the two states are connected in the
set of states' graph.
Because the state space is implicit—a typical state space graph would be too vast to build
and maintain in-memory—state space search often deviates from conventional computer
science search techniques. Instead, new nodes are created as they are visited and then
frequently destroyed. In combinatorial search, a solution can be either the final state or
a sequence of states that lead from an initial state to the final state.
Features:
A state space is a set of all possible states that it can reach from the current state.
The nodes of a state space represent states, and the arcs connecting them represent
actions.
A path is a set of states and the actions that link them in the state space.
A problem's solution is a node in the graph representing all possible states of the
problem.
Most AI techniques are based on state space representation.
Advantages:
It is very useful in AI because of it provides a set of all possible states, operations and
goals.
If the entire state space is for a problem then it is possible to trace the path from the initial
to the goal state and identify the sequence of operation required for doing it.
Disadvantages:
It is not possible to visualize all states for a problem.
The resources of the computer system are very limited to handle huge combinational state
space.
PIET - DS (CE)
12
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
The rules in a production system are determined by LHS (left-hand side) and RHS (right-
hand side) equations, where LHS denotes the specific condition to be applied, and RHS
shows the output of the applied condition.
3. List out Production Systems characteristics for State Space Search. (3M)
There are mainly four characteristics of the production system in AI that Is-
1. Implicity
2. Modifiability
3. Modularity
4. knowledge-intensive.
PIET - DS (CE)
13
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Simplicity
The production rule in AI is in the form of an ‘IF-THEN’ statement. Every rule in the
production system has a unique structure. It helps represent knowledge and reasoning in
the simplest way possible to solve real-world problems. Also, it helps improve the
readability and understanding of the production rules.
Modularity
The modularity of a production rule helps in its incremental improvement as the production
rule can be in discrete parts. The production rule is made from a collection of information
and facts that may not have dependencies unless there is a rule connecting them together.
The addition or deletion of single information will not have a major effect on the output.
Modularity helps enhance the performance of the production system by adjusting the
parameters of the rules.
Modifiability
The feature of modifiability helps alter the rules as per requirements. Initially, the skeletal
form of the production system is created. We then gather the requirements and make
changes in the raw structure of the production system. This helps in the iterative
improvement of the production system.
Knowledge-intensive
Production systems contain knowledge in the form of a human spoken language, i.e.,
English. It is not built using any programming languages. The knowledge is represented in
plain English sentences. Production rules help make productive conclusions from these
sentences.
PIET - DS (CE)
14
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
It includes Blind Search, Uninformed Search, and Blind control strategy. These search
techniques are not always possible as they require much memory and time. These
techniques search the complete space for a solution and use the arbitrary ordering of
operations.
The examples of Direct Heuristic search techniques include Breadth-First Search (BFS)
and Depth First Search (DFS).
It includes Informed Search, Heuristic Search, and Heuristic control strategy. These
techniques are helpful when they are applied properly to the right types of tasks. They
usually require domain-specific information.
PIET - DS (CE)
15
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
The examples of Weak Heuristic search techniques include Best First Search (BFS) and
A*.
Generate-and-Test
Generate-and-test search algorithm is a very simple algorithm that guarantees to find
solution if done systematically and there exists a solution.
Algorithm:
1. Generate a possible solution. For some problems, this means generating a particular
point in the problem space. For others it means generating a path from a start stat.
2. Test to see if this is actually a solution by comparing the chosen point or the endpoint
of the chosen path to the set of acceptable goal states.
3. If a solution has been found, quit, Otherwise return to step 1.
It is a depth first search procedure since complete solutions must be generated before they can
be tested.
In its most systematic form, it is simply an exhaustive search of the problem space.
It operates by generating solutions randomly.
Ridge: is a special kind of local maximum. It is an area of the search space that is higher than
surrounding areas and that itself has slop.
In each of the previous cases (local maxima, plateaus & ridge), the algorithm
reaches a point at which no progress is being made.
A solution is,
1. Backtrack to some earlier node and try going in a different direction.
2. Make a big jump to try to get in a new section.
3. Moving in several directions at once.
1. Local Maxima: a local maximum is a state that is better than all its neighbors but is not
better than some other states further away.
2. Plateau: a plateau is a flat area of the search space in which, a whole set of neighboring
states have the same values.
PIET - DS (CE)
17
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Solution. The equivalent search tree for the above graph is as follows. As DFS traverses the tree
“deepest node first”, it would always pick the deeper branch until it reaches the solution (or it runs
out of nodes, and goes to the next branch). The traversal is shown in blue arrows.
.For each way that each rule can match the state described in E do:
. Apply the rule to generate a new state.
a. If the new state is a goal state, quit and return this state.
b. Otherwise, add the new state to the end of NODE-LIST.
PIET - DS (CE)
19
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
A goal state is any state that has been constrained “enough” where “enough” must be
defined for each problem.
For example, in cryptarithmetic problems, enough means that each letter has been
assigned a unique numeric value.
Constraint Satisfaction problems in AI have goal of discovering some problem state
that satisfies a given set of constraints.
Design tasks can be viewed as constraint satisfaction problems in which a design must
be created within fixed limits on time, cost, and materials.
Constraint Satisfaction is a two-step process:
o First constraints are discovered and propagated as far as possible throughout the
system.
o Then if there is still not a solution, search begins. A guess about something is
made and added as a new constraint.
Algorithm: Constraint Satisfaction
1. Propagate available constraints. To do this first set OPEN to set of all objects that must have
values assigned to them in a complete solution. Then do until an inconsistency is detected or
until OPEN is empty:
a) Select an object OB from OPEN. Strengthen as much as possible the set of constraints
that apply to OB.
b) If this set is different from the set that was assigned the last time OB was examined or
if this is the first time OB has been examined, then add to OPEN all objects that share
any constraints with OB.
c) Remove OB from OPEN.
2. If the union of the constraints discovered above defines a solution, then quit and report the
solution.
3. If the union of the constraints discovered above defines a contradiction, then return the
failure. 4. If neither of the above occurs, then it is necessary to make a guess at something in
order to proceed. To do this loop until a solution is found or all possible solutions have been
eliminated:
a) Select an object whose value is not yet determined and select a way of strengthening
the constraints on that object.
b) Recursively invoke constraint satisfaction with the current set of constraints augmented
by strengthening constraint just selected.
Collection of strategies presented so far can reason either forward or backward, but for a
given problem, one direction or the other must be chosen.
A mixture of the two directions is appropriate. Such a mixed strategy would make it
possible to solve the major parts of a problem first and then go back and solve the small
problems that arise in “gluing” the big pieces together.
The technique of Means-Ends Analysis (MEA) allows us to do that.
PIET - DS (CE)
20
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
MEA process centers around the detection of differences between the current state and the
goal state.
Once such a difference is isolated, an operator that can reduce the difference must be found.
If the operator cannot be applied to the current state, we set up a sub-problem of getting to
a state in which it can be applied.
The kind of backward chaining in which operators are selected and then sub-goals are set
up to establish the preconditions of the operators is called operator sub-goaling.
1. Compare CURRENT to GOAL. If there are no differences between them then return.
2. Otherwise, select the most important difference and reduce it by doing the following until
success or failure is signaled:
a) Select an as yet untried operator O that is applicable to the current difference. If there are
no such operators, then signal failure.
b) Attempt to apply O to CURRENT. Generate descriptions of two states: OSTART, a state
in which O’s preconditions are satisfied and O-RESULT, the state that would result if O
were applied in O-START.
c) If (FIRST-PART MEA( CURRENT, O-START)) and (LAST-PART MEA(O-
RESULT, GOAL)) are successful, then signal success and return the result of
concatenating FIRST-PART, O, and LAST-PART.
we know the initial state and goal state as given below. In this problem, we need to get the goal
state by finding differences between the initial state and goal state and applying operators.
Solution:
To solve the above problem, we will first find the differences between initial states and goal states,
and for each difference, we will generate a new state and will apply the operators. The operators
we have for this problem are:
Move
Delete
Expand
PIET - DS (CE)
21
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
1. Evaluating the initial state: In the first step, we will evaluate the initial state and will compare
the initial and Goal state to find the differences between both states.
2. Applying Delete operator: As we can check the first difference is that in goal state there is no
dot symbol which is present in the initial state, so, first we will apply the Delete operator to remove
this dot.
3. Applying Move Operator: After applying the Delete operator, the new state occurs which we
will again compare with goal state. After comparing these states, there is another difference that is
the square is outside the circle, so, we will apply the Move Operator.
4. Applying Expand Operator: Now a new state is generated in the third step, and we will compare
this state with the goal state. After comparing the states there is still one difference which is the
size of the square, so, we will apply Expand operator, and finally, it will generate the goal state.
PIET - DS (CE)
22
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
1. Declarative Knowledge:
2. Procedural Knowledge
3. Meta-knowledge:
PIET - DS (CE)
23
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
4. Heuristic knowledge:
5. Structural knowledge:
PIET - DS (CE)
24
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Perception
Learning
Knowledge Representation and Reasoning
Planning
Execution
The above diagram is showing how an AI system can interact with the real world and what
components help it to show intelligence.
AI system has Perception component by which it retrieves information from its
environment. It can be visual, audio or another form of sensory input.
The learning component is responsible for learning from data captured by Perception
comportment.
In the complete cycle, the main components are knowledge representation and Reasoning.
These two components are involved in showing the intelligence in machine-like humans.
These two components are independent with each other but also coupled together. The
planning and execution depend on analysis of Knowledge representation and reasoning.
PIET - DS (CE)
25
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Player1 65 23
Player2 58 18
Player3 75 24
2. Inheritable knowledge:
In the inheritable knowledge approach, all data must be stored into a hierarchy of classes.
All classes should be arranged in a generalized form or a hierarchal manner.
In this approach, we apply inheritance property.
Elements inherit values from other members of a class.
This approach contains inheritable knowledge which shows a relation between instance
and class, and it is called instance relation.
Every individual frame can represent the collection of attributes and its value.
In this approach, objects and values are represented in Boxed nodes.
We use Arrows which point from objects to their values
Example:
PIET - DS (CE)
26
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
3. Inferential knowledge:
Inferential knowledge approach represents knowledge in the form of formal logics.
This approach can be used to derive more facts.
It guaranteed correctness.
Example: Let's suppose there are two statements:
o Marcus is a man
o All men are mortal
Then it can represent as;
man(Marcus)
∀x = man (x) --------- > mortal (x)s
4. Procedural knowledge:
Procedural knowledge approach uses small programs and codes which describes how to do
specific things, and how to proceed.
In this approach, one important rule is used which is If-Then rule.
In this knowledge, we can use various coding languages such as LISP
language and Prolog language.
We can easily represent heuristic or domain-specific knowledge using this approach.
But it is not necessary that we can represent all cases in this approach.
PIET - DS (CE)
27
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
1. Representational Accuracy:
KR system should have the ability to represent all kind of required knowledge.
2. Inferential Adequacy:
KR system should have ability to manipulate the representational structures to produce new
knowledge corresponding to existing structure.
3. Inferential Efficiency:
The ability to direct the inferential knowledge mechanism into the most productive
directions by storing appropriate guides.
4. Acquisitional efficiency
The ability to acquire the new knowledge easily using automatic methods.
PIET - DS (CE)
28
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Image Recognition:
Example Facebook Automatic friend tagging suggestion
Speech Recognition:
Example Google assistant, Siri, Cortana, and Alexa
Traffic prediction:
Example
Traffic prediction:
Example Google Map
Product recommendation
Example Amazon, Netflix
Self-driving cars
Example Tesla
PIET - DS (CE)
29
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Medical Diagnosis
Example 3D models that can predict the exact position of lesions in the brain
2. What Are the Three Stages of Building a Model in Machine Learning? (3M)
Machine learning typically follows three phases:
1. Training: A training set of examples of correct behavior is analyzed and some representation
of the newly learnt knowledge is stored. This is some form of rules.
2. Validation: The rules are checked and, if necessary, additional training is given. Sometimes
additional test data are used, but instead, a human expert may validate the rules, or some other
automatic knowledge based component may be used. The role of the tester is often called the
opponent.
3. What Are the Differences Between Machine Learning and Human Learning?
(3M)
Advantages
It helps in solving complex real-world problems which are difficult to be solved by
general techniques.
The learning model of RL is similar to the learning of human beings; hence most
accurate results can be found.
Helps in achieving long term results.
Disadvantage
RL algorithms are not preferred for simple problems.
RL algorithms require huge data and computations.
Too much reinforcement learning can lead to an overload of states which can weaken
the results.
PIET - DS (CE)
31
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
PIET - DS (CE)
32
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
If there is only one input variable (x), then such linear regression is called simple linear
regression. And if there is more than one input variable, then such linear regression is called
multiple linear regression.
The relationship between variables in the linear regression model can be explained using
the below image. Here we are predicting the salary of an employee on the basis of the year
of experience.
PIET - DS (CE)
33
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
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 K-NN working can be explained on the basis of the below algorithm:
Applications of KNN:
Text Mining
Agriculture
Finance
Medical
Facial Recognition
Recommendation systems(Amazon, Hulu, Netflix, etc)
PIET - DS (CE)
34
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Advantages
It is very easy to understand and implement.
If we have large number of variables then, K-means would be faster than Hierarchical
clustering.
On re-computation of centroids, an instance can change the cluster.
Tighter clusters are formed with K-means as compared to Hierarchical clustering.
Disadvantages
It is a bit difficult to predict the number of clusters i.e. the value of k.
Output is strongly impacted by initial inputs like number of clusters (value of k).
Order of data will have strong impact on the final output.
It is very sensitive to rescaling. If we will rescale our data by means of normalization or
standardization, then the output will completely change.final output.
It is not good in doing clustering job if the clusters have a complicated geometric shape.
PIET - DS (CE)
35
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
The Apriori Algorithm is an influential algorithm for mining frequent itemsets for boolean
association rules.
Apriori uses a "bottom up" approach, where frequent subsets are extended one item at a
time (a step known as candidate generation, and groups of candidates are tested against
the data.
Apriori is designed to operate on database containing transactions (for example, collections
of items bought by customers, or details of a website frequentation).
Frequent Itemsets: All the sets which contain the item with the
minimum support (denoted by 𝐿𝑖 for 𝑖𝑡ℎ itemset).
Apriori Property: Any subset of frequent itemset must be frequent.
Join Operation: To find 𝐿𝑘, a set of candidate k-itemsets is generated by joining 𝐿𝑘−1 with
itself.
STEP 1
Scan the transaction data base to get the support of S each 1-itemset, compare S with min_sup, and
get a support of 1-itemsets, L1
STEP 2
Use 𝐿𝑘−1 join 𝐿𝑘−1 to generate a set of candidate k-itemsets. And use Apriori property to prune
the unfrequented k-itemsets from this set.
STEP 3
Scan the transaction database to get the support S of each candidate k-itemset in the find set,
compare S with min_sup, and get a set of frequent k-itemsets 𝐿𝑘
PIET - DS (CE)
36
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
STEP 4
The candidate set = Null
STEP 5
For each frequent itemset 1, generate all nonempty subsets of 1
STEP 6
For every nonempty subset s of 1, output the rule “s=>(1-s)” if confidence C of the rule “s=>(1-
s)” (=support s of 1/support S of s)’ min_conf
PIET - DS (CE)
37
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
It creates an adaptive system that computers use to learn from their mistakes and improve
continuously. Thus, artificial neural networks attempt to solve complicated problems, like
summarizing documents or recognizing faces, with greater accuracy.
Neural networks can help computers make intelligent decisions with limited human
assistance. This is because they can learn and model the relationships between input and
output data that are nonlinear and complex. For instance, they can do the following tasks.
Feedforward neural networks process data in one direction, from the input node to the
output node. Every node in one layer is connected to every node in the next layer. A
feedforward network uses a feedback process to improve predictions over time.
2. Backpropagation algorithm
Artificial neural networks learn continuously by using corrective feedback loops to improve their
predictive analytics. Only one path is the correct one that maps the input node to the correct output
node. To find this path, the neural network uses a feedback loop, which works as follows:
Each node makes a guess about the next node in the path.
It checks if the guess was correct. Nodes assign higher weight values to paths that lead to
more correct guesses and lower weight values to node paths that lead to incorrect guesses.
For the next data point, the nodes make a new prediction using the higher weight paths and
then repeat Step 1.
They are very useful for image classification because they can extract relevant features
from images that are useful for image recognition and classification. The new form is easier
to process without losing features that are critical for making a good prediction. Each
hidden layer extracts and processes different image features, like edges, color, and depth.
PIET - DS (CE)
38
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
20
Rima Female Football
PIET - DS (CE)
39
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
PIET - DS (CE)
40
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
PIET - DS (CE)
41
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
PIET - DS (CE)
42
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
2. EXAMPLE:(4M)
Apply KNN classification on the following dataset and predict the quality of paper_5 having Acid
Durability = 7 and Strength = 5 for K= 3 (Nearest Neighbor). (4M) The below table shows
four training samples
Paper_1 7 4 Good
Paper_2 7 3 Good
Paper_3 3 4 Bad
Paeper_4 5 3 Bad
PIET - DS (CE)
43
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
PIET - DS (CE)
44
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
PIET - DS (CE)
45
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
3. EXAMPLE:(4M)
Apply KNN classification on the following dataset and predict the quality
of paper_5 having AcidDurability = 7 and Strength = 5 for K= 3 (Nearest
Neighbor). (4M)The below table shows four training samples
Paper_1 7 4 Good
Paper_2 7 3 Good
Paper_3 3 4 Bad
Paeper_4 5 3 Bad
PIET - DS (CE)
46
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Step 1
First, Number of parameters K = Number of nearest neighbors.
Therefore, from the given data K = 3
Step 2
Calculate the distance between the query instance and all the training samples.
Here query instance is (3,7) and calculates the distance by using the Euclidean Distance
formula
The below table shows the Euclidean Distance for every paper from the query instance (3,
7):
Step 3
Sort the distance and determine the nearest neighbors based on Kth
minimum distance
The below table shows the sorted distance and according to that nearest neighbor is decided
for each paper:
PIET - DS (CE)
47
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Step 4
Collect the Quality of the nearest neighbors. Hence in the below, table Quality for Paper_2
is not included because the rank of this paper item is more than 3.
The below table shows the quality of each paper based on the nearest neighbor:
4. EXAMPLE:(4M)
“ Restaurant A” sells burgers with optional flavors: Pepper, Ginger, and Chilly. Every day
this week you have tried a burger (A to E) and kept a record of which you liked show how
the 3NN classifier with majority voting would classify
{ pepper: false, ginger: true, chilly: true}
Training Examples:
PIET - DS (CE)
48
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
The following table shows the distance between the new example and the training example,
calculated using hamming distance.
Next, Based on the distance we find 3 nearest neighbors (3NN), which are marked in the
last column.
PIET - DS (CE)
49
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
1+0+0
A True True True False 2
=1
1+1+1
B True False False True
=3
0+0+0
C False True True False 1
=0
0+0+1
D False True False True 2
=1
1+1+1
E True False False True
=3
Finally, majority voting is used to assign the classification label to the new example. In this
case, we have, two False and one True nearest examples. Hence the new example is
classified as FLASE.
5. EXAMPLE: (4M)
Find a linear regression equation for the following two sets of data:
x 2 4 6 8
y 3 7 5 10
Solution:
Construct the table and find the value
X y x² xy
2 3 4 6
4 7 16 28
6 5 36 30
8 10 64 80
Σx = Σy = Σx² = Σxy =
20 25 120 144
6. Example (4M)
The values of y and their corresponding values of y are shown in the table below
x 0 1 2 3 4
y 2 3 5 4 6
Solution
a) We use a table to calculate a and b.
PIET - DS (CE)
51
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
X y xy x2
0 2 0 0
1 3 3 1
2 5 10 4
3 4 12 9
4 6 24 16
Σx = Σy = Σx y = Σx2 =
10 20 49 30
We now calculate a and b using the least square regression formulas for a and b.
7. Example: (4M)
Suppose we have the following dataset that has various transactions, and from this dataset,
we need to find the frequent itemsets and generate the association rules using the Apriori
algorithm:
PIET - DS (CE)
52
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Solution:
Step-1: Calculating C1 and L1:
In the first step, we will create a table that contains support count (The frequency of each
itemset individually in the dataset) of each itemset in the given dataset. This table is called
the Candidate set or C1.
Now, we will take out all the itemsets that have the greater support count that the Minimum
Support (2). It will give us the table for the frequent itemset L1.
Since all the itemsets have greater or equal support count than the minimum support, except
the E, so E itemset will be removed.
In this step, we will generate C2 with the help of L1. In C2, we will create the pair of the
itemsets of L1 in the form of subsets.
After creating the subsets, we will again find the support count from the main transaction
table of datasets, i.e., how many times these pairs have occurred together in the given
dataset. So, we will get the below table for C2:
Again, we need to compare the C2 Support count with the minimum support count, and
after comparing, the itemset with less support count will be eliminated from the table C2.
It will give us the below table for L2
PIET - DS (CE)
53
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Now we will create the L3 table. As we can see from the above C3 table, there is only one
combination of itemset that has support count equal to the minimum support count. So, the
L3 will have only one combination, i.e., {A, B, C}.
To generate the association rules, first, we will create a new table with the possible rules
from the occurred combination {A, B.C}. For all the rules, we will calculate the Confidence
using formula sup( A ^B)/A. After calculating the confidence value for all rules, we will
exclude the rules that have less confidence than the minimum threshold(50%).
Consider the below table:
PIET - DS (CE)
54
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
As the given threshold or minimum confidence is 50%, so the first three rules A ^B → C,
B^C → A, and A^C → B can be considered as the strong association rules for the given
problem.
8. Example: (4M)
Support threshold=50%, Confidence= 60%
TABLE-1
Transaction List of items
T1 I1,I2,I3
T2 I2,I3,I4
T3 I4,I5
T4 I1,I2,I4
T5 I1,I2,I3,I5
T6 I1,I2,I3,I4
Solution:
TABLE-2
Item Count
I1 4
I2 5
I3 4
I4 4
I5 2
TABLE -2 shows that I5 item does not meet min_sup=3, thus it is deleted, only I1, I2, I3,
I4 meet min_sup count.
TABLE-3
Item Count
I1 4
I2 5
I3 4
PIET - DS (CE)
55
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Item Count
I4 4
TABLE -4 shows that item set {I1, I4} and {I3, I4} does not meet min_sup, thus it is
deleted.
TABLE-5
Item Count
I1,I2 4
I1,I3 3
I2,I3 4
I2,I4 3
Form 3-itemset. From the TABLE- 1 find out occurrences of 3-itemset. From TABLE-5,
find out the 2-itemset subsets which support min_sup.
We can see for itemset {I1, I2, I3} subsets, {I1, I2}, {I1, I3}, {I2, I3} are occurring
in TABLE-5 thus {I1, I2, I3} is frequent.
We can see for itemset {I1, I2, I4} subsets, {I1, I2}, {I1, I4}, {I2, I4}, {I1, I4} is not
frequent, as it is not occurring in TABLE-5 thus {I1, I2, I4} is not frequent, hence it is
deleted.
TABLE-6
Item
I1,I2,I3
I1,I2,I4
I1,I3,I4
I2,I3,I4
Only {I1, I2, I3} is frequent.
6. Generate Association Rules: From the frequent itemset discovered above the
association could be:
{I1, I2} => {I3}
Confidence = support {I1, I2, I3} / support {I1, I2} = (3/ 4)* 100 = 75%
{I1, I3} => {I2}
Confidence = support {I1, I2, I3} / support {I1, I3} = (3/ 3)* 100 = 100%
{I2, I3} => {I1}
Confidence = support {I1, I2, I3} / support {I2, I3} = (3/ 4)* 100 = 75%
PIET - DS (CE)
56
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
9. Example: (4M)
Let us solve a numerical problem on k means clustering. The problem is as follows. You are given
15 points in the Cartesian coordinate system as follows. K=3
Point Coordinates
A1 (2,10)
A2 (2,6)
A3 (11,11)
A4 (6,9)
A5 (6,4)
A6 (1,2)
A7 (5,10)
A8 (4,9)
A9 (10,12)
A10 (7,5)
A11 (9,11)
A12 (4,6)
A13 (3,10)
A14 (3,8)
A15 (6,11)
PIET - DS (CE)
57
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
First, we will randomly choose 3 centroids from the given data. Let us consider A2 (2,6), A7
(5,10), and A15 (6,11) as the centroids of the initial clusters. Hence, we will consider that
Centroid 1=(2,6) is associated with cluster 1.
Centroid 2=(5,10) is associated with cluster 2.
Centroid 3=(6,11) is associated with cluster 3.
Now we will find the euclidean distance between each point and the centroids. Based on the
minimum distance of each point from the centroids, we will assign the points to a cluster.
PIET - DS (CE)
58
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
In cluster 1, we have 6 points i.e. A2 (2,6), A5 (6,4), A6 (1,2), A10 (7,5), A12 (4,6), A14
(3,8). To calculate the new centroid for cluster 1, we will find the mean of the x and y
coordinates of each point in the cluster. Hence, the new centroid for cluster 1 is (3.833,
5.167).
In cluster 2, we have 5 points i.e. A1 (2,10), A4 (6,9), A7 (5,10) , A8 (4,9), and A13 (3,10).
Hence, the new centroid for cluster 2 is (4, 9.6)
In cluster 3, we have 4 points i.e. A3 (11,11), A9 (10,12), A11 (9,11), and A15 (6,11).
Hence, the new centroid for cluster 3 is (9, 11.25).
Now that we have calculated new centroids for each cluster, we will calculate the distance
of each data point from the new centroids. Then, we will assign the points to clusters based
on their distance from the centroids.
PIET - DS (CE)
59
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
Now, we will calculate the new centroid for each cluster for the third iteration.
In cluster 1, we have 5 points i.e. A2 (2,6), A5 (6,4), A6 (1,2), A10 (7,5), and A12 (4,6).
To calculate the new centroid for cluster 1, we will find the mean of the x and y coordinates
of each point in the cluster. Hence, the new centroid for cluster 1 is (4, 4.6).
In cluster 2, we have 7 points i.e. A1 (2,10), A4 (6,9), A7 (5,10) , A8 (4,9), A13 (3,10),
A14 (3,8), and A15 (6,11). Hence, the new centroid for cluster 2 is (4.143, 9.571)
In cluster 3, we have 3 points i.e. A3 (11,11), A9 (10,12), and A11 (9,11). Hence, the new
centroid for cluster 3 is (10, 11.333).
PIET - DS (CE)
60
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
In cluster 1, we have 5 points i.e. A2 (2,6), A5 (6,4), A6 (1,2), A10 (7,5), and A12 (4,6).
To calculate the new centroid for cluster 1, we will find the mean of the x and y coordinates
of each point in the cluster. Hence, the new centroid for cluster 1 is (4, 4.6).
In cluster 2, we have 7 points i.e. A1 (2,10), A4 (6,9), A7 (5,10) , A8 (4,9), A13 (3,10),
A14 (3,8), and A15 (6,11). Hence, the new centroid for cluster 2 is (4.143, 9.571)
In cluster 3, we have 3 points i.e. A3 (11,11), A9 (10,12), and A11 (9,11). Hence, the new
centroid for cluster 3 is (10, 11.333).
Here, you can observe that no point has changed its cluster compared to the previous iteration. Due
to this, the centroid also remains constant. Therefore, we will say that the clusters have been
PIET - DS (CE)
61
ARTIFICIAL INTELLIGENCE AND MACHINE LEARNING (03606387)
stabilized. Hence, the clusters obtained after the third iteration are the final clusters made from the
given dataset. If we plot the clusters on a graph, the graph looks like as follows.
PIET - DS (CE)
62