Lab Workbook
Lab Workbook
Team ML
K L UNIVERSITY | MACHINE LEARNING – 17CS3166
17CS3166 MACHINE LEARNING
LABORATORY WORKBOOK
STUDENT NAME
REG. NO
YEAR
SEMESTER
SECTION
FACULTY
1
17CS3166 MACHINE LEARNING
Table of Contents
Organization of the STUDENT LAB WORKBOOK ..................................................................................... 3
LAB EXPERIMENT #1: Preprocessing of data .......................................................................................... 6
LAB EXPERIMENT #2: Linear Regression Model.................................................................................... 14
LAB EXPERIMENT #3: Decision Tree learning model ............................................................................ 22
LAB EXPERIMENT #4: Implement the Random forest learning model ................................................. 30
LAB EXPERIMENT #5: K-Nearest Neighbors Model............................................................................... 38
LAB EXPERIMENT #6: Naïve Bayes classification Model ....................................................................... 46
LAB EXPERIMENT #7: K-Means Clustering Model ................................................................................. 57
LAB EXPERIMENT #8: Hierarchical clustering Model ............................................................................ 65
LAB EXPERIMENT #9: Support Vector Machine Model ........................................................................ 72
LAB EXPERIMENT #10: Artificial Neural Network Model - I .................................................................. 79
LAB EXPERIMENT #11: Artificial Neural Network Model - II ................................................................. 87
LAB EXPERIMENT #12: Using TensorFlow Model for implementing Neural Network.......................... 93
LAB EXPERIMENT #13: Developing GUI application using Tkinter package ......................................... 99
LAB EXPERIMENT #14:Develop a solution for Knapsack problem using Genetic Algorithm .............. 105
2
17CS3166 MACHINE LEARNING
The laboratory framework includes a creative element but shifts the time-intensive
aspects outside of the Two-Hour closed laboratory period. Within this structure, each
laboratory includes three parts: Pre-lab, In-lab, and Post-lab.
a. Pre-Lab
The Pre-lab exercise is a homework assignment that links the lecture with the
laboratory period - typically takes 2 hours to complete. The goal is to synthesize the
information they learn in lecture with material from their textbook to produce a
working piece of software. Pre-lab Students attending a two-hour closed laboratory
are expected to make a good-faith effort to complete the Pre-lab exercise before
coming to the lab. Their work need not be perfect, but their effort must be real
(roughly 80 percent correct).
b. In-Lab
The In-lab section takes place during the actual laboratory period. The First hour of
the laboratory period can be used to resolve any problems the students might have
experienced in completing the Pre-lab exercises. The intent is to give constructive
feedback so that students leave the lab with working Pre-lab software - a significant
accomplishment on their part. During the second hour, students complete the In-lab
exercise to reinforce the concepts learned in the Pre-lab. Students leave the lab having
received feedback on their Pre-lab and In-lab work.
c. Post-Lab
The last phase of each laboratory is a homework assignment that is done following the
laboratory period. In the Post-lab, students analyse the efficiency or utility of a given
system call. Each Post-lab exercise should take roughly 120 minutes to complete.
NOTE : Additional files are required for the completion of lab tasks. These files can be
downloaded from the repository below :
http://bit.ly/KLUMLLAB
3
17CS3166 MACHINE LEARNING
1 Preprocessing of data
4
17CS3166 MACHINE LEARNING
In-Lab Viva-
Sl Pre-Lab Post Lab Total Faculty
Date Experiment Name LOGIC EXECUTION RESULT ANALYSIS Voce
No (5M) (5M) (50M) Signature
(10M) (10M) (10M) (5M) (5M)
a) Estimate the centroid value for the
given dataset using K-means clustering
7
b) Apply K means clustering for the flight
delay dataset using MS-Azure
a) Based on Agglomerative clustering
identify the countries having similar GDP
8 and literacy rate
b) Using MS-Azure, build the K-means
clustering for the countries dataset.
a) Construct SVM model for the
employee dataset to predict the
9 promotion status
b) Using MS-Azure predict the cancelled
flights and estimate the accuracy
Using the Artificial Neural Network,
10 generate the output for the given data
5
17CS3166 MACHINE LEARNING
References:
1. https://www.geeksforgeeks.org/data-preprocessing-machine-learning-python/
2. https://towardsdatascience.com/introduction-to-data-preprocessing-in-machine-
learning-a9fa83a5dc9d
Pre-Lab Task:
1. Why is the pandas library used and give some examples of classes in the pandas
library?
2. Why is the numpy library used what are the classes in that library?
6
17CS3166 MACHINE LEARNING
3. Why matplotlib is used and what are the different classes in it?
4. Why the sklearn library used and what is are the different classes in it?
7
17CS3166 MACHINE LEARNING
In-Lab Task:
NOTE: In machine learning, we create a model and we use that model in the real world for
prediction. For creating that model initially we have to process the data. Our machine
learning can understand only numerical data, not the categorical data so we have to convert
categorical data to numerical data while training the model.
1. There is an MNC company which produces a product ‘I’. Now we have a record of
information about purchases of previous years based on COUNTRY, AGE and SALARY.
Now we have to perform data preprocessing which deals with
8
17CS3166 MACHINE LEARNING
9
17CS3166 MACHINE LEARNING
10
17CS3166 MACHINE LEARNING
Viva-voce:
1. What is a dataset?
11
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. What is Feature scaling and what are its uses?
12
17CS3166 MACHINE LEARNING
13
17CS3166 MACHINE LEARNING
References:
1. https://www.geeksforgeeks.org/regression-classification-supervised-machine-
learning
2. https://www.geeksforgeeks.org/linear-regression-python-implementation
3. https://towardsdatascience.com/introduction-to-machine-learning-algorithms-
linear-regression-14c4e325882a
Pre-Lab Task:
1. What are the types of Machine Learning? Explain briefly about each type.
2. What is linear regression? What are the different types of linear regression?
14
17CS3166 MACHINE LEARNING
In-Lab Task:
1. There is a company named ML which is recruiting employees. The company has a record
of salaries of the previous employees and their years of experience. Now the newcomers
are expecting high pay but the company wants to pay the fair amount. So build a linear
regression machine learning model to help the company to pay the fair pay based on their
experience. Write a python code using sklearn and predict the salary when the employee
who has experience of 8 years.
15
17CS3166 MACHINE LEARNING
16
17CS3166 MACHINE LEARNING
2. Import the energy efficient regression data from azure database and select columns in
data set, clean the missing data, split the data, train the model using simple linear
regression(select all the dependent columns) and finally evaluate the model.
1. Find accuracy
17
17CS3166 MACHINE LEARNING
18
17CS3166 MACHINE LEARNING
Viva-voce:
1. What is regression?
3. What evaluation metric can be used to evaluate a model while a continuous output
variable?
4. A statistical model is said to be over fitted when it is trained with a lot of data(true or
false).
19
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. A person wants to build a new website which can predict the profit of the company based
on given features: R&D spends, Marketing spends, Administration spends and in which
state it is located. He possesses some dataset so by using this dataset build a multiple linear
regression model.
20
17CS3166 MACHINE LEARNING
21
17CS3166 MACHINE LEARNING
References:
1. https://www.xoriant.com/blog/product-engineering/decision-trees-machine-
learning-algorithm.html
2. https://saedsayad.com/decision_tree_reg.htm
Pre-Lab Task:
1. What is a Decision tree?
2. What is the difference between Decision tree classification and Decision tree
regression?
22
17CS3166 MACHINE LEARNING
In-Lab Task:
a) The sports committee of state wants to provide sports programs to children of state but
they are not sure about their participation. So they conduct a survey on children as how
many hours they play based on weather conditions. So we need to build a machine
learning model which can predict the amount of time children plays based on given
weather condition. In supervised learning, this is a regression problem. So, build a decision
tree using decision tree regression model on the given dataset. Write a python code for
building this model using sklearn and predict the hours played when
23
17CS3166 MACHINE LEARNING
24
17CS3166 MACHINE LEARNING
b) The sports committee of state wants to provide sports programs to children of state but
they are not sure about their participation. So they conduct a survey on children as how
many hours they play based on weather conditions. So we need to build a machine
learning model which can predict whether children plays based on given weather
condition. In supervised learning, this is a classification problem. So, build a decision tree
using decision tree classification model by using given dataset. Write a python code for
building this model using sklearn and predict whether they play or not for the given value
25
17CS3166 MACHINE LEARNING
26
17CS3166 MACHINE LEARNING
Viva-voce:
1. Why do we use entropy in a decision tree?
27
17CS3166 MACHINE LEARNING
Post-Lab Task:
2. Import adult census dataset from azure dataset and build a decision tree model and
evaluate the result in Microsoft Azure machine learning.
age: 52, work class: Private, education: Masters, nation: Cuba, Income: <50k
28
17CS3166 MACHINE LEARNING
29
17CS3166 MACHINE LEARNING
References:
1. https://www.datascience.com/resources/notebooks/random-forest-intro
2. https://towardsdatascience.com/random-forest-in-python-24d0893d51c0
Pre-Lab Task:
1. What is Random Forest learning?
4. What is the difference between Random Forest Classification and Random forest
regression?
30
17CS3166 MACHINE LEARNING
In-Lab Task:
a. There are many students who have attended for GRE and TOEFL exam and their scores
are in the dataset. Along with their scores, the Universities will also be considering their
CVs for qualification, based on which the students will get the qualification status.
Now help your friend to predict his qualification status based on the above dataset using
random forest classification. His marks are as follows:
31
17CS3166 MACHINE LEARNING
32
17CS3166 MACHINE LEARNING
b. There is a small country called Guinea, where petrol consumption is playing a crucial role
in their country’s economy. So, the government wants to predict and restrict the
consumption of petrol. They possess the data of the last 50 years on petrol consumption
which depends upon petrol tax, average income, paved highways, and population driver
license. Now build a random forest regression model to help the government of Guinea.
33
17CS3166 MACHINE LEARNING
34
17CS3166 MACHINE LEARNING
Viva-voce:
35
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. Import adult census dataset from azure dataset and build a random forest model and
evaluate the result in Microsoft Azure machine learning studio.
1. Find accuracy
36
17CS3166 MACHINE LEARNING
37
17CS3166 MACHINE LEARNING
References:
1. https://towardsdatascience.com/machine-learning-basics-with-the-k-nearest-neighbors-
algorithm-6a6e71d01761
2. https://www.saedsayad.com/k_nearest_neighbors.htm
Pre-Lab Task:
1. What are the different types of distance metrics in K-nearest Neighbors algorithm?
2. What does the value of ‘K’ denote and how do we decide its value?
38
17CS3166 MACHINE LEARNING
In-Lab Task:
a) Suppose you are in a shopping mall, you have to buy a t-shirt for your friend’s birthday.
But the problem here is you don’t know anything except his height and weight. Based on
that predict the size of the t-shirt given the height and weight of the person. Use KNN
algorithm for the following.
[158, 28]
39
17CS3166 MACHINE LEARNING
40
17CS3166 MACHINE LEARNING
b) There is a selection going on for Guards at parade grounds. Unfortunately, the weighing
machine is not working. We can get their ‘Age’ from their CV and measuring tape to
measure the height. From the previous year's dataset, take age, height as criteria and
build a machine learning KNN regression model which can predict the weight. Now take K
value from 1 to 8 and find the root. Mean square error for each value of K and find the
value of K with the least root mean square error.
41
17CS3166 MACHINE LEARNING
42
17CS3166 MACHINE LEARNING
Viva-voce:
1. What are some applications of KNN?
43
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. There is a dataset without any columns. But, you need to use it for the mathematical
calculations. Without columns names, it is not possible. Assign column names as “X” and
“Y” to the dataset using “Python script” in Azure ML Studio.
44
17CS3166 MACHINE LEARNING
45
17CS3166 MACHINE LEARNING
References:
1. https://towardsdatascience.com/naive-bayes-in-machine-learning-f49cc8f831b4
2. https://en.wikipedia.org/wiki/Naive_Bayes_classifier
Pre-Lab:
1. Define Bayes Theorem.
46
17CS3166 MACHINE LEARNING
In-Lab Task:
a) There is a company named QWE which releases a new product and they want to know
who will buy the product based on the given features gender, age, estimated price. Build
a naive Bayes classifier model to help the company to know who will buy the product.
Divide the data set into training and testing data and also print the confusion matrix.
47
17CS3166 MACHINE LEARNING
48
17CS3166 MACHINE LEARNING
b) Import blood donation dataset from azure dataset and build a naive BAYES classifier.
Model and evaluate the result in Microsoft Azure machine learning studio.
49
17CS3166 MACHINE LEARNING
50
17CS3166 MACHINE LEARNING
Viva-voce:
51
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. There are three neighbors. One of them has a grandfather who is suffering from heart and
breathing problems. The person should go to work but he couldn’t leave his grandfather
alone. So he will be setting an emergency alarm for his grandfather to ring in case of any
danger. He intimates his neighbors to call him at any cost if they hear the alarm.
There are some chances that the neighbors couldn’t respond properly. The first person
may not be able to hear the alarm if they are very far away from the house. The second person
is a music lover so he/she will be listening with high volume so he/she may not be able to
hear the alarm. So, these are the two cases where the two persons may not respond.
Given:
52
17CS3166 MACHINE LEARNING
H B P(A=T) P(A=F)
T T 0.95 0.05
T F 0.95 0.06
F T 0.28 0.72
F F 0.005 0.995
A (P1=T) P(P1=F)
T 0.94 0.06
F 0.53 0.47
A P(P2=T) P(P2=F)
T 0.10 0.90
F 0.10 0.90
53
17CS3166 MACHINE LEARNING
54
17CS3166 MACHINE LEARNING
55
17CS3166 MACHINE LEARNING
56
17CS3166 MACHINE LEARNING
References:
1. https://medium.com/@sparshtemani31415/k-means-clustering-algorithm-
258bd752042
2. https://www.datascience.com/blog/k-means-clustering
Pre-Lab:
1. What is clustering?
57
17CS3166 MACHINE LEARNING
In-Lab Task:
a) We have both annual income and spending score of different people stored in a dataset.
Now we have to tell which person belongs to which category. Use the K-means clustering
algorithm for the following dataset. Take k=5 and print centroid value for each cluster.
58
17CS3166 MACHINE LEARNING
59
17CS3166 MACHINE LEARNING
b) Import the flight delay dataset from azure database, apply k means clustering model. With
k value =2 and k-means++ algorithm and visualize the output in Microsoft azure machine
learning studio.
60
17CS3166 MACHINE LEARNING
61
17CS3166 MACHINE LEARNING
Viva-voce:
1. Can you find clustering in student sitting in the lab?
2. Clustering is learned with the example having (data and label or only data)?
3. In K-means clustering, what are the methods to find the distance measure?
62
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. Write an algorithm for K-means++?
63
17CS3166 MACHINE LEARNING
64
17CS3166 MACHINE LEARNING
References:
1. https://www.thelearningmachine.ai/hierarchical
2. https://www.datanovia.com/en/lessons/agglomerative-hierarchical-clustering/
Pre-Lab Task:
65
17CS3166 MACHINE LEARNING
In-Lab Task:
a) A survey conducted by the Times of India shows the GDP of the country and the literacy
rate of the country. Now using agglomerative algorithm cluster the countries which are
having a similar GDP and literacy rate.
66
17CS3166 MACHINE LEARNING
67
17CS3166 MACHINE LEARNING
b) Import the flight delay dataset from azure database, apply k means clustering model.
With k value =2 and First 2 values as initial means and visualize the output in Microsoft
azure machine learning studio.
68
17CS3166 MACHINE LEARNING
69
17CS3166 MACHINE LEARNING
Viva-voce:
1. What are the different types of hierarchical clustering algorithms.
70
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. Discuss in brief about decisive clustering.
71
17CS3166 MACHINE LEARNING
References:
1. https://medium.com/machine-learning-101/chapter-2-svm-support-vector-machine-
theory-f0812effc72
Pre-Lab Task:
1. What is SVM?
72
17CS3166 MACHINE LEARNING
In-Lab Task:
a) A company is in confusion to give the promotion to their employees and so construct SVM
model to help the management by using previous year’s data which includes visualizing
the testing and training set results and also predict the promotion status for an
employee who has age experience of 30 years and salary of 45000.
73
17CS3166 MACHINE LEARNING
74
17CS3166 MACHINE LEARNING
b) Import flight delays data from the Azure database and construct the support vector
machine learning model and evaluate the result using Microsoft Azure machine learning
studio.
Month: 10, day of month: 14, day of week: 4, origin airport id: 12451, destination
airport id: 10397.
Writing space for the Problem: (For Student’s use only)
75
17CS3166 MACHINE LEARNING
76
17CS3166 MACHINE LEARNING
Viva-voce:
1. What is generalization error in terms of the SVM?
77
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. Discuss in brief about kernel SVM?
Writing space for the Problem: (For Student’s use only)
78
17CS3166 MACHINE LEARNING
References:
1. https://towardsdatascience.com/nns-aynk-c34efe37f15a
In-Lab Task:
Build an artificial neural network from scratch by taking 3 input neurons and 1 output
neurons. Use 4 hidden neurons in between and use activation function as sigmoid
function. Use any loss function like mean squared error function also use gradient
descent algorithm to find weights for synapses. Finally generate the output for the
given data [1,1,0]
0 0 1 0
0 1 1 1
1 0 1 1
1 1 1 0
79
17CS3166 MACHINE LEARNING
80
17CS3166 MACHINE LEARNING
Viva-voce:
1. What is CNN? Explain it with an application.
81
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. Build a neural network for regression by taking no of hours studied, no of hours slept
and we need to predict the score out of 100 that he scored in exam. So build a neural
network regression model which as 2 input neurons, 3 hidden neurons and 1 output
layer. Use activation function as sigmoid function, use any loss function and use gradient
descent for finding accurate values of synapses. Now predict the values for [6,5].
82
17CS3166 MACHINE LEARNING
83
17CS3166 MACHINE LEARNING
84
17CS3166 MACHINE LEARNING
2. Import Bill gates RGB image data from the Azure database and construct the support
Neural network model and evaluate the result using Microsoft Azure machine learning
studio.
a. Find the accuracy
b. Predict the green cells with the following data
X: 0, y: 94, R: 18, B: 91
Writing space for the Problem: (For Student’s use only)
85
17CS3166 MACHINE LEARNING
86
17CS3166 MACHINE LEARNING
References:
1. https://towardsdatascience.com/nns-aynk-c34efe37f15a
Pre-Lab Task:
1. What is Deep learning?
87
17CS3166 MACHINE LEARNING
In-Lab Task:
There is an MNC company and they want to know the number of employees will be
working by the end of the year. The exit status of an employee will depend on their credit
Score, Geography, Gender, Age, tenure, balance, no of products, hascrcard, is an active
member, estimated salary. They also possess the previous year’s data so help the
company by building a neural network model.
88
17CS3166 MACHINE LEARNING
89
17CS3166 MACHINE LEARNING
Viva-voce:
1. List some commercial practical applications of Artificial Neural Networks.
3. Perceptron receives input signals and if the sum of the input signals exceeds and
certain threshold value, it either outputs a signal or does not return any output?
90
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. Import the adult census data from Azure dataset and build a model which consists of
decision tree model, random forest model, logistic regression model, SVM model and find
which machine learning algorithm gives the better prediction for that dataset .Use cross
validation.
Writing space for the Problem: (For Student’s use only)
91
17CS3166 MACHINE LEARNING
92
17CS3166 MACHINE LEARNING
References:
1. https://www.tensorflow.org/tutorials
Pre-Lab Task:
1. What are types of errors used in TensorFlow? Write syntax any of the two errors?
3. What is the major difference between constant, variable and placeholder in Tensor
flow?
93
17CS3166 MACHINE LEARNING
In-Lab Task:
There is a scientist named Jack Sparrow. Jack Sparrow builds a robot. He wants to teach
his robot to recognize numbers. So he wants to build a model using Tensor flow, but he
doesn’t know TensorFlow and he has no time to learn TensorFlow. So he asks his all friends
to build a model using TensorFlow so he can pick the model with high accuracy and you
are one of his friends so help your friend by building a model ?(hint: use
“MNIST_data” dataset from TensorFlow.
Writing space for the Problem: (For Student’s use only)
94
17CS3166 MACHINE LEARNING
95
17CS3166 MACHINE LEARNING
Viva-voce:
1) What are the applications of deep learning?
2) What is the difference between simple neural network and convolutional neural
networks?
96
17CS3166 MACHINE LEARNING
Post-Lab Task:
1) Display how many images are used for training?
97
17CS3166 MACHINE LEARNING
98
17CS3166 MACHINE LEARNING
References:
1. https://www.geeksforgeeks.org/python-gui-tkinter/
Pre-Lab Task:
1. Create a simple window using Tkinter.
2. A person clicked on a tkinter button with button text “K L University”. A new window
popped up with display text “Welcome to K L University”. Now, write a python code
for implementing this.
3. What is Canvas?
99
17CS3166 MACHINE LEARNING
In-Lab Task:
Mahesh owns a real estate business. He is so worried about his business because the
interest rates and stock index prices are fluctuating. But, he doesn’t know any
programming. For solving this issue, he wants to have a GUI application which is user-
friendly and can predict the stock index price based on the interest rate. Help Mahesh by
developing a user-friendly GUI application (Based on Linear regression) for him.
100
17CS3166 MACHINE LEARNING
101
17CS3166 MACHINE LEARNING
Viva-voce:
1. What is GUI, how is it used in our University?
3. What is Tkinter?
102
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. Mahesh later realized that not only the interest rate but also other factors like Year,
Month and unemployment rate can affect the stock index price. On considering all these
factors, develop a new GUI application (Based on Multiple Linear regression) for him
which can predict the stock index prices for him.
Writing space for the Problem: (For Student’s use only)
103
17CS3166 MACHINE LEARNING
104
17CS3166 MACHINE LEARNING
References:
1. https://www.analyticsvidhya.com/blog/2017/07/introduction-to-genetic-algorithm/
Pre-Lab Task:
1. What is meant by population and fitness function?
105
17CS3166 MACHINE LEARNING
In-Lab Task:
You’re taking a backpack with you; however, the maximum weight it can carry is 20
kilograms. You have a number of survival items available, each with its own number of
survival points. You’re objective is to maximize the number of survival points. The data
is given as follows:
106
17CS3166 MACHINE LEARNING
107
17CS3166 MACHINE LEARNING
Viva-voce:
1. What is evolutionary computing?
4. What is a chromosome?
108
17CS3166 MACHINE LEARNING
Post-Lab Task:
1. What are the applications, disadvantages, advantages over gradient descent?
Writing space for the Problem: (For Student’s use only)
109
17CS3166 MACHINE LEARNING
110
17CS3166 MACHINE LEARNING
SKILL WORKBOOK
17CS3166 MACHINE LEARNING
Team ML
K L UNIVERSITY | MACHINE LEARNING – 17CS3166
i
17CS3166 MACHINE LEARNING
SKILL WORKBOOK
STUDENT NAME
REG. NO
YEAR
SEMESTER
SECTION
FACULTY
ii
17CS3166 MACHINE LEARNING
Table of Contents
Exercise #1: Creation of data set using Pandas ......................................................................................... 1
Exercise #2: Data Manipulation using Numpy .......................................................................................... 4
Exercise #3: Constructing a linear regression model .............................................................................. 13
Exercise #4: Constructing Decision Tree model ...................................................................................... 16
Exercise #5: Naïve Bayes Classification................................................................................................... 18
Exercise #6: Basic operations on TensorFlow ......................................................................................... 20
Exercise #7: Regression using TensorFlow.............................................................................................. 24
Exercise #8: Logistic Regression using TensorFlow ................................................................................. 27
Exercise #9: K – Means Clustering using TensorfFow.............................................................................. 30
Exercise #10: Basic Operations using Opencv ......................................................................................... 33
Exercise #11: Image Processing using Opencv ........................................................................................ 36
Exercise #12: Video capturing using Opencv .......................................................................................... 40
iii
17CS3166 MACHINE LEARNING
iv
17CS3166 MACHINE LEARNING
Signature
Viva Total
Observation Logic Execution Result Analysis of
S.No Date Aim Voce Marks
(10M) (5M) (10M) (10 M) (5 M) Faculty
(10M) (50M)
with date
Basic operations on
6
TensorFlow
v
17CS3166 MACHINE LEARNING
Signature
Viva Total
Observation Logic Execution Result Analysis of
S.No Date Aim Voce Marks
(10M) (5M) (10M) (10 M) (5 M) Faculty
(10M) (50M)
with date
vi
17CS3166 MACHINE LEARNING
A) INTRODUCTION TO PANDAS
1. Load the data set and print the data in csv file?
2. Find the sum of all columns in that csv file?
3. Load and just first two columns from all the rows?
4. Plot the graph of the dataset without matplotlib?
5. Find the mean of all the columns?
6. Find the mode, minimum, absolute, standard deviation of the data set?
1
17CS3166 MACHINE LEARNING
2
17CS3166 MACHINE LEARNING
3
17CS3166 MACHINE LEARNING
4
17CS3166 MACHINE LEARNING
11) Generate the graph by using given data as in the given diagram
y=[2.56422, 3.77284,3.52623, 3.51468, 3.02199] ,z = [0.15, 0.3, 0.45, 0.6,
0.75] ,n = ['dheeraj', 'vamsi', 'satish', 'basha', 'kartik'].
12) Explain the definition and uses of the following graphs in detail:
1. Factor plot
2. Density plot
3. Box whiskers plot
5
17CS3166 MACHINE LEARNING
13) Consider the above data and plot the following graphs and explain them
briefly:
i) Bar Plot for analyzing whether ‘Y’ values are increasing with ‘X’ with
width=1/1.5 and in blue colour.
ii) Check the frequency distribution of all ‘Y’ values for 20 bins.
iii) Identify the mean and medians of the ‘Y’ values by plotting a horizontal
notched box-whiskers plot. (The mean should be identified as a point in the graph).
14) Create a random10 X 5 numpy matrix. Convert it into a data frame (Using
pandas) with column names =’A’, ‘B’, ‘C’, ‘D’ and ‘E’. Now, analyze the data
frame by drawing an area plot.
ii) Create a random numpy array of size 3. Create a data frame named
‘Dishes’ using the created array with indexes=’ Cup Cake’, ‘Bread’ and ‘Cookie’.
Let us assume the values of the array indicate how much a person likes the
respective dishes. Now, draw a Pie plot and identify his/her most liked dish.
6
17CS3166 MACHINE LEARNING
16) What are the uses of the seaborn library? How is it different from matplotlib?
17) In the above dataset, Imagine ‘E’ is the dependent variable and ‘A’, ‘B’, and
‘C’ are independent. using Heatmap, determine which among ‘A’, ‘B’ and ‘C’ has
a high impact on ‘E’.
7
17CS3166 MACHINE LEARNING
8
17CS3166 MACHINE LEARNING
9
17CS3166 MACHINE LEARNING
10
17CS3166 MACHINE LEARNING
11
17CS3166 MACHINE LEARNING
12
17CS3166 MACHINE LEARNING
model
Date of the Session: ___/___/___
Time of the Session: _____to______
Build a simple linear regression model using numpy, pandas, matplotlib and write
the python code mathematically.
Download the dataset
https://drive.google.com/file/d/1mHJraLU5HWkLq6Kaaq8Khc2MDz_u_Bru/view?usp=sharing
13
17CS3166 MACHINE LEARNING
14
17CS3166 MACHINE LEARNING
15
17CS3166 MACHINE LEARNING
You are having a blood donor data taken from the blood transfusion service center
now using the data build a decision tree machine learning model to predict the
respective person is willing to donate the blood or not.
16
17CS3166 MACHINE LEARNING
17
17CS3166 MACHINE LEARNING
We have a sample data set of adult census income across the globe now using the
data build a Naïve Bayes machine learning model to predict their class based on
their gender, capital gain, capital loss, hours per week and find the accuracy of
your model
18
17CS3166 MACHINE LEARNING
19
17CS3166 MACHINE LEARNING
1) Create two constants and do addition for those constants and print the result
using tensorflow?
2) Create two placeholders and do addition for those placeholders and print the
result using tensorflow?
3) Create two Variables and do addition for those Variables and print the result
using tensorflow?
4) Create one variable, one placeholder, one constant and do multiplication and
print the value?
5) Create 4X4 matrix and fill with default value as zeros using tensorflow?
6) Using random function create 4X4 matrix with values range 0<x<1?
7) Do the following:
i. Create a 4X4 matrix having mean =0 and stddev=1.0 using random()
in tensorflow in singleline?
ii. Create a 4X4 matrix in range minval=0 and maxval=1.0 using
random() in tensorflow in singleline?
iii. Perform multiplication for above two matrices and print then using
tensorflow in single line?
8) using linspace command write a code in tensorflow?
9) Create two tensorflow objects and initialize the values at run time and add
them and now create a tensor board graph using then in tensorflow?
10) perform a scatter plot using tensorflow with the flowing given data
a=[1,2,3,4,5] and b=[3.5,2.2,1,4,9] ?
20
17CS3166 MACHINE LEARNING
21
17CS3166 MACHINE LEARNING
22
17CS3166 MACHINE LEARNING
23
17CS3166 MACHINE LEARNING
Create a dataset of 100000 using line space and generate noise of size 100000
using np.random.randn
Create and run the session and plot the respective line.4
x=[3.3,4.4,5.5,6.71,6.93,4.168,9.779,6.182,7.59,2.167,
7.042,10.791,5.313,7.997,5.654,9.27,3.1]
y=[1.7,2.76,2.09,3.19,1.694,1.573,3.366,2.596,2.53,1.221,
2.827,3.465,1.65,2.904,2.42,2.94,1.3]
24
17CS3166 MACHINE LEARNING
25
17CS3166 MACHINE LEARNING
26
17CS3166 MACHINE LEARNING
Learning rate=0.01
Training epochs=25
Batch size=100
Display step=1
Use softmax and matmul to predict the output using the matrices.
27
17CS3166 MACHINE LEARNING
28
17CS3166 MACHINE LEARNING
29
17CS3166 MACHINE LEARNING
30
17CS3166 MACHINE LEARNING
31
17CS3166 MACHINE LEARNING
32
17CS3166 MACHINE LEARNING
1) Write a program which takes a image and give a Title as ‘My Image’
.Display it in gray scale using opencv?
2) Write a program to reshape the image as 10X8 using opencv?
3) Write a program to convert a image BGR TO RBG and save it using
opencv?
4) Write a program to write a name on image and display it using opencv?
5) write a program to read an image from camera and save it as frames when
we click space bar and stop it when we click ‘ESC’ button using opencv?
33
17CS3166 MACHINE LEARNING
34
17CS3166 MACHINE LEARNING
35
17CS3166 MACHINE LEARNING
2)load an image and split that into red,blue,green channels and display each
channel and merge them again and display the image.
3)load an image with help of open CV and make the following operations
a)make blue and green colour to zero and print the image.
b) make blue and red colour to zero and print the image.
c) make red and green colour to zero and print the image.
4)create a black colour rectangle with open cv and build a circle and a triangle in
between the rectangle?
5)create the black colour rectangle with openCV and wite your name in it.
36
17CS3166 MACHINE LEARNING
37
17CS3166 MACHINE LEARNING
38
17CS3166 MACHINE LEARNING
39
17CS3166 MACHINE LEARNING
1) Write a program to run a video which is present in our system in a gray scale
using opencv?
2) Write a program to capture a video in HSV, GRAY, RGB using opencv?
3) Write a program to capture a video in HSV, GRAY and save the video in
HSV using csv?
4) Write a program to calculate the height and width of a frame and print them
and set the height, width of the frame to ([3,3000], [4,3000] using opencv?
5) Do the following using opencv:
i. Write a program to keep text like width, height on the frame which
is visualize from camera?
ii. Write a program to keep date and time on the frame which is
visualize from camera
40
17CS3166 MACHINE LEARNING
41
17CS3166 MACHINE LEARNING
42
17CS3166 MACHINE LEARNING
43