21UCS608 AI&ML Lab Manual
21UCS608 AI&ML Lab Manual
LAB MANUAL
SEMESTER: VI
CORE VALUES
Quality Commitment Innovation Team Courtesy
work
QUALITY POLICY
To provide Quality technical education to the students
To produce competent professionals and contributing citizens
To contribute for the upliftment of the society
DEPARTMENT VISION
To achieve excellence in technical education and scientific research in the field of computer
science and engineering to contribute to the society.
DEPARTMENT MISSION
Transforming students into technocrats in computer technology confirming the industry
expectation.
Imparting holistic learner centric environment.
Cultivating interpersonal traits, problem solving skills, critical and rationale thinking
capabilities for the development of students leading to innovators, leaders and
entrepreneurs.
Establishing collaboration with the industries for mutual benefits.
Promoting Research activities among the students and the faculty to solve problems
related to industry and society.
Offering computer applications life skill to society for better living.
CORE VALUES
Quality Dedication Novelty Team work Courtesy
PROGRAM OUTCOMES
Apply the knowledge of mathematics, basic sciences, engineering fundamentals, and
1.
Computer Science and Engineering to the solution of complex engineering problems.
(Engineering Knowledge)
Identify, formulate, review research literature and analyze complex engineering problems
2.
requiring computing solutions to reach substantiated conclusions using first principles of
mathematics, basic sciences, and Computer Science and Engineering. (Problem analysis)
Design solutions for computer applied complex engineering problems and design system
3. components or processes that meet the specified needs with appropriate consideration for
the public health and safety, and the cultural, societal, and environmental considerations.
(Design/development of solutions)
Use research-based knowledge and research methods including design of experiments,
4.
analysis and interpretation of data, and synthesis of the information to provide valid
conclusions. (Conduct investigations of complex problems)
Create, Select and apply appropriate techniques, resources, and modern IT tools including
5.
prediction and modeling to computing related complex engineering activities with an
understanding of the limitations. (Modern tool usage)
Apply reasoning informed by the contextual knowledge to assess societal, health, safety,
6.
legal and cultural issues and the consequent responsibilities relevant to the professional
computer science and engineering practice. (The Engineer and society)
Understand the impact of the professional computer science and engineering solutions in
7.
societal and environmental contexts, and demonstrate the knowledge of, and need for
sustainable development. (Environment and sustainability)
8. Apply ethical principles and commit to professional ethics and responsibilities and norms
of the computer science and engineering practice. (Ethics)
9. Function effectively as an individual, and as a member or leader in diverse teams, and in
multidisciplinary settings. (Individual and team work)
Communicate effectively on complex computer science and engineering activities with the
10. engineering community and with society at large, such as, being able to comprehend and
write effective reports and design documentation, make effective presentations, and give
and receive clear instructions. (Communication)
Demonstrate knowledge and understanding of the engineering and management principles
11.
and apply these to one’s own work, as a member and leader in a team, to manage cost
effective projects in multidisciplinary environments.(Project management and finance)
12. Recognize the need for, and have the preparation and ability to engage in independent and
life-long learning in the broadest context of technological change. (Life-long learning)
21UCS608 ARTIFICIAL INTELLIGENCE AND L T P C
MACHINE LEARNING LABORATORY
0 0 2 1
PRE-REQUISITE :
COURSE OBJECTIVES:
Implementing the basic concepts in Artificial Intelligence.
Implementing Machine Learning Algorithms.
LIST OF EXPERIMENTS
1. Implement Breadth First Search (for 8 puzzle problem or Water jug problem or any AI search
problem).
2. Implement Depth First Search (for 8-queen problem or 8 puzzle problem or Water jug problem
or any AI search problem).
3. Solve travelling salesperson problem using Best First Search.
4. Build a Knowledge based system for forecasting the weather.
5. Write a program to construct a Bayesian network considering medical data. Use this model to
demonstrate the diagnosis of heart patients using standard Heart Disease Data Set.
6. Demonstrate the working of decision tree based on ID3 algorithm. Use an appropriate data
set for building the decision tree and apply this knowledge to classify the new sample.
7. Construct model to predict the residential home prize as a function of the homes living area.
8. Develop a model to determine the likelihood of a patient’s successful response to a specific
medical treatment.
9. Develop an algorithm to predict whether a particular customer buy a computer or not based on
the following attribute age, income, student and credit rating.
10. Develop a model to predict stock market using machine learning algorithm.
TOTAL : 30 Periods
COURSE OUTCOMES:
After the successful completion of this course, the student will be able to
Implement the concepts of Artificial Intelligence and Machine Learning to solve the real world
problems. (Apply)
Analyze various Artificial Intelligence and Machine Learning techniques for the effective
solution for a given problem. (Analyze)
Evaluate the performance of a machine learning model using various parameters. (Evaluate)
Develop machine learning models to find the optimal solution for the given real world
scenario. (Create)
Communicate effectively to justify the solutions to the given problems based on legal and
ethical principles. (Affective domain)
Work effectively as an individual or in teams to develop machine learning models for the
given problem. (Affective domain)
LESSON PLANNING SHEET
Methodology
(D-Demo,
L-Lab visit)
S.No Lesson /Topic Covered Session
Lab Support
(LS)
D L
Write a python program to construct the water jug problem using
1. 1
Breadth First Search
Write a python program to construct N-Puzzle problem using Depth
2. 1
First Search
3. Solve travelling salesperson problem using Best First Search 1
4. Build a Knowledge based system for forecasting the weather 1
Write a program to construct a Bayesian network considering
5. medical data. Use this model to demonstrate the diagnosis of heart 1
patients using standard Heart Disease Data Set
Develop an algorithm to predict whether a particular customer buy a
6. computer or not based on the following attribute age, income, 1
student and credit rating.
Demonstrate the working of decision tree based on ID3 algorithm.
7. Use an appropriate data set for building the decision tree and apply 1
this knowledge to classify the new sample
Construct model to predict the residential home prize as a function
8.
of the homes Living area
1
Develop a model to determine the likelihood of a patient’s
9.
successful response to a specific medical treatment
Problem: There are two jugs of volume A litre and B litre. Neither has any measuring mark
on it. There is a pump that can be used to fill the jugs with water. How can you get exactly x
litre of water into the A litre jug. Assuming that we have unlimited supply of water.
Let us assume, we have A=4 litre and B= 3 litre jugs. And we want exactly 2 Litre water into
jug A (i.e 4 litre jug) how we will do this.
Solution:
The state space for this problem can be described as the set of ordered pairs of integers (x,y)
where, x represents the quantity of water in the 4-gallon jug and x= 0,1,2,3,4; y represents the
quantity of water in 3-gallon jug and y = 0,1,2,3
Start State: (0,0)
Goal State: (2,0)
Generate production rules for the water jug problem. We basically perform three operations to
achieve the goal.
1. Fill water jug.
2. Empty water jug
3. and Transfer water jug
We start at an initial state in the queue where both the jugs are empty. We then continue to
explore all the possible intermediate states derived from the current jug state using the operations
provided.
We also, maintain a visited matrix of states so that we avoid revisiting the same state of jugs
again and again.
So, we proceed, keeping in mind all the valid state cases (as shown in the table above) and we
do a BFS on them.
In the BFS, we skip the state which was already visited or if the amount of water in either of the
jugs exceeded the jug quantity. If we continue further, then we mark the current state as visited
and check if in this state, if we have obtained the target quantity of water in either of the jugs, we
can empty the other jug and return the current state’s entire path.
But, if we have not yet found the target quantity, we then derive the intermediate states from the
current state of jugs i.e. we derive the valid cases, mentioned in the table above. We keep
repeating all the above steps until we have found our target or there are no more states left to
proceed with.
Ex. No.2 8-Puzzle Problem using Breadth First Search
Problem statement:
The N-puzzle consists of N tiles (N+1 titles with an empty tile) where N can be 8, 15, 24 and so
on. Let us assume that N = 8. (that is square root of (8+1) = 3 rows and 3 columns). In the
same way, if we have N = 15, 24, then they have Row and columns as follows (square root of
(N+1) rows and square root of (N+1) columns). That is if N=15 than number of rows and
columns= 4, and if N= 24 number of rows and columns= 5.
In these types of problems, we have given an initial state or initial configuration and a Goal
state or Goal Configuration. Here, we solve a problem of 8 puzzle that is a 3x3 matrix.
1 2 3
4 6
7 5 8
Solution:
The puzzle can be solved by moving the tiles one by one in the single empty space and thus
achieving the Goal state.
Instead of moving the tiles in the empty space we can visualize moving the empty space in place
of the tile. The empty space can only move in four directions (Movement of empty space)
1. Up
2. Down
3. Right or
4. Left
The empty space cannot move diagonally and can take only one step at a time.
All possible move of a Empty tile
o- Position total possible moves are (2), x - position total possible moves are (3) and
#-position total possible moves are (4)
Consider the following situation. You are given a list of n cities with the distance between any
two cities. Now, you have to start with your office and to visit all the cities only once each and
return to your office. What is the shortest path can you take? This problem is called the Traveling
Salesman Problem (TSP).
Best-first search
In the Best-first search, we use the information of distance from the root node to decide which
node to visit first. Let g(X) be the distance from the root node to node-X. Therefore, the distance
from the root node to node-Y by visiting node-X is g(Y)=g(X)+d(X, Y), where d(X, Y) is the
distance between X and Y.
Knowledge
Humans reason based on existing knowledge and draw conclusions. The concept of representing
knowledge and drawing conclusions from it is also used in AI, and in this lecture we will explore
how we can achieve this behaviour.
Knowledge-Based Agents
These are agents that reason by operating on internal representations of knowledge. Consider the
Harry Potter example with the following sentences:
1. If it didn’t rain, Harry visited Hagrid today.
2. Harry visited Hagrid or Dumbledore today, but not both.
3. Harry visited Dumbledore today.
Based on these three sentences, we can answer the question “did it rain today?”, even though
none of the individual sentences tells us anything about whether it is raining today. Here is how
we can go about it: looking at sentence 3, we know that Harry visited Dumbledore. Looking at
sentence 2, we know that Harry visited either Dumbledore or Hagrid, and thus we can conclude
4. Harry did not visit Hagrid.
Now, looking at sentence 1, we understand that if it didn’t rain, Harry would have visited Hagrid.
However, knowing sentence 4, we know that this is not the case. Therefore, we can conclude
5. It rained today.
To come to this conclusion, we used logic, and today’s lecture explores how AI can use logic to
reach to new conclusions based on existing information.
Ex. No.5 Bayesian Network for Medical Data
Write a program to construct a Bayesian network considering medical data. Use this model
to demonstrate the diagnosis of heart patients using standard Heart Disease Data Set.
Procedure:
Using the table of step 1, The mathematics calculation will be like below for the feature Outlook:
Step 7: Finding the most informative feature (feature with highest information gain)
Like Outlook feature, we have to calculate information gain for every feature in the dataset.
Then we have to select the feature with the highest information gain. As the feature Outlook has
the highest value, so it will be selected for our tree node.
Now, if any value of the feature represents only one class then we can say that the feature value
represents a pure class. If the value does not represent a pure value, we have to extend it further.
We have generated the tree. Now, we can use the tree for prediction. We will recursively traverse
the nested dictionary until any leaf node (= class) is found. Remember that, the key of the
dictionary is feature name which is the datatype of string, and the value is either a dictionary
which means we have to traverse the tree more or any basic datatype like string or int or float
depending on the class data type, which means it’s a leaf node.
To evaluate the model i.e. the tree we need a labeled test dataset. Then after predicting we can
calculate the difference of actual and predicted value in percentage.
If we print the accuracy, we will get 1.00 which means our accuracy is 100% correct.
Ex.No.8
Linear Regression is a Supervised Machine Learning Model for finding the relationship
between independent variables and dependent variable. Linear regression performs the task to
predict the response (dependent) variable value (y) based on a given (independent) explanatory
variable (x). So, this regression technique finds out a linear relationship between x (input) and y
(output).
Predicting house prices can help to determine the selling price of a house of a particular
region and can help people to find the right time to buy a home. In this model on House Price
Prediction using machine learning, use data from the California census to create a machine
learning model to predict house prices in the State. The data includes features such as population,
median income, and median house prices for each block group in California.
Ex. No.9
Develop a model to determine the likelihood of a patient's successful
response to a specific medical treatment
AIM:-. To write a python program to analyze a medical data set . Breast cancer dataset has been
used for analysis purpose.
PROCEDURE:
Breast cancer (BC) is one of the most common cancers among women worldwide, representing
the majority of new cancer cases and cancer-related deaths according to global statistics, making
it a significant public health problem in todays society.
The early diagnosis of BC can improve the prognosis and chance of survival significantly, as it
can promote timely clinical treatment to patients.
Because of its unique advantages in critical features detection from complex BC datasets,
machine learning (ML) is widely recognized as the methodology of choice in BC pattern
classification and forecast modelling.
Classification and data mining methods are an effective way to classify data.
Especially in medical field, where those methods are widely used in diagnosis and analysis to
make decisions
Attribute Information:
1) ID number
2) Diagnosis (M = malignant, B = benign)
3-32) Ten real-valued features are computed for each cell nucleus:
a) radius (mean of distances from center to points on the perimeter)
b) texture (standard deviation of gray-scale values)
c) perimeter
d) area
e) smoothness (local variation in radius lengths)
f) compactness (perimeter^2 / area – 1.0)
g) concavity (severity of concave portions of the contour)
h) concave points (number of concave portions of the contour)
i) symmetry
j) fractal dimension (“coastline approximation” – 1)
A stock market is a public market where you can buy and sell shares for publicly listed
companies. The stocks, also known as equities, represent ownership in the company. The stock
exchange is the mediator that allows the buying and selling of shares.
From the image on the top, you can see LSTMs have a chain-like structure. General RNNs have
a single neural network layer. LSTMs, have four interacting layers communicating
extraordinarily. LSTMs work in a three-step process.
The first step in LSTM is to decide which information to be omitted from the cell in that
particular time step. It is decided with the help of a sigmoid function. It looks at the previous
state (ht-1) and the current input xt and computes the function.
There are two functions in the second layer. The first is the sigmoid function, and the second
is the tanh function. The sigmoid function decides which values to let through (0 or 1). The
tanh function gives the weightage to the values passed, deciding their level of importance
from -1 to 1.
The third step is to decide what will be the final output. First, you need to run a sigmoid layer
which determines what parts of the cell state make it to the output. Then, you must put the
cell state through the tanh function to push the values between -1 and 1 and multiply it by the
output of the sigmoid gate.
Ex.No.11
Develop a model to predict the values using clustering method
AIM:-
To write a python program to construct the model using k means clustering method.
PROCEDURE:-
Step 1 – First, we need to specify the number of clusters, K, need to be generated by this
algorithm.
Step 2 – Next, randomly select K data points and assign each data point to a cluster. In simple
words, classify the data based on the number of data points.
Step 3 – Now it will compute the cluster centroids.
Step 4 – Next, keep iterating the following until we find optimal centroid which is the
assignment of data points to the clusters that are not changing any more.