0% found this document useful (0 votes)
412 views160 pages

Lab Workbook

Imputer is used to handle missing data by replacing missing values with constant values like mean, median etc. OneHotEncoder is used to convert categorical features into numerical features by creating dummy variables. This is important for algorithms that cannot handle categorical data directly.

Uploaded by

Oye Aj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
412 views160 pages

Lab Workbook

Imputer is used to handle missing data by replacing missing values with constant values like mean, median etc. OneHotEncoder is used to convert categorical features into numerical features by creating dummy variables. This is important for algorithms that cannot handle categorical data directly.

Uploaded by

Oye Aj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 160

LAB WORKBOOK

17CS3166 MACHINE LEARNING

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

Organization of the STUDENT LAB WORKBOOK

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

2019-20 ODD SEMESTER LAB CONTINUOUS EVALUATION

In-Lab Post Viva


Sl Pre-Lab Total Faculty
Date Experiment Name LOGI EXECUTION RESULT ANALYSIS Lab Voce
No (5M) (50M) Signature
C (10M) (10M) (5M) (5M) (5M)
(10M)

1 Preprocessing of data

a) Construct a linear regression model for


prediction
2
b) Build a linear regression model for the
energy efficiency dataset
a) Construct a decision tree, to predict the
number of hours played
3
b) Construct a decision tree for the play
tennis problem to predict play or not
a) Using Random Forest algorithm, predict
the qualification status of the candidates
4
b) Using Random Forest algorithm,
predict the petrol consumption
a) Using KNN algorithm, predict the size of
the T-shirt given the height and weight of
5 the person
b) Predict the average weight of the
person given the age for the given dataset
a) Estimate the probability of buying the
product based on Naïve Bayes
6 b) Predict the occupation of the donors
from blood donation dataset from MS-
Azure

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

Using the Neural network model predict


11 the number of employees who will be
working at the end of the year
Using TensorFlow, build a Neural
12 Network model to recognize numbers

Develop a GUI application with Tinketer


13 package to predict the stock price using
linear regression model
Develop a ML model for solving a
14 Knapsack problem using Genetic
Algorithm

5
17CS3166 MACHINE LEARNING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 17CS3166
MACHINE LEARNING

LAB EXPERIMENT #1: Preprocessing of data

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

5. Why do we use imputer and OneHotEncoder?

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

a. Importing the libraries


b. Importing the dataset
c. Dealing with missing data
d. Dealing with categorical data
e. Splitting the dataset into training and testing data.

Download the dataset(s) from the repository.

Writing space for the Problem: (For Student’s use only)

8
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

9
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

10
17CS3166 MACHINE LEARNING

Viva-voce:
1. What is a dataset?

2. What are the ways to access a dataset?

3. How can we import the dataset?

4. What is the purpose of preprocessing the dataset?

5. Why do we use LabelEncoder?

11
17CS3166 MACHINE LEARNING

Post-Lab Task:
1. What is Feature scaling and what are its uses?

2. For the same dataset perform the feature scaling.

12
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

13
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #2: Linear Regression Model

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

3. What is Loss Function? Why do we use it?

4. What is gradient descent?

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.

Download the dataset(s) from the repository.

Writing space for the Problem: (For Student’s use only)

15
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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

2. Predict the given model with following values.

Heating load: 24.57, predict the cooling load.

Writing space for the Problem: (For Student’s use only)

17
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

18
17CS3166 MACHINE LEARNING

Viva-voce:
1. What is regression?

2. How to find the best regression line?

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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

20
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

21
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #3: Decision Tree learning model

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

3. In Decision tree classification, how do you identify the root node?

4. What is ID3 algorithm and how do we use it in 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

[rainy, hot, low, FALSE]

Download the dataset(s) from the repository.

Writing space for the Problem: (For Student’s use only)

23
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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

[sunny, cool, high, TRUE]


Download the dataset(s) from the repository.

Writing space for the Problem: (For Student’s use only)

25
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

26
17CS3166 MACHINE LEARNING

Viva-voce:
1. Why do we use entropy in a decision tree?

2. What is Standard deviation and how do we use it?

3. What types of data can be handled by decision trees?

4. What are the ways of avoiding over fitting in a decision tree?

27
17CS3166 MACHINE LEARNING

Post-Lab Task:

1. What are the issues in Decision tree learning?

2. Import adult census dataset from azure dataset and build a decision tree model and
evaluate the result in Microsoft Azure machine learning.

1. Find the accuracy


2. Predict the occupation for the following dataset

age: 52, work class: Private, education: Masters, nation: Cuba, Income: <50k

28
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

29
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #4: Implement the Random forest learning model

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

2. Distinguish between Random forest learning and decision tree learning?

3. What is bootstrap data and out of bag error?

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:

GRE: 335, TOEFL: 112, CV: weak


Download the dataset(s) from the repository..

Writing space for the Problem: (For Student’s use only)

31
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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.

Now predict petrol consumption for the following data:


Download the dataset(s) from the repository.

Writing space for the Problem: (For Student’s use only)

33
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

34
17CS3166 MACHINE LEARNING

Viva-voce:

1. What is ensemble learning explain with example?

2. How is a Decision tree different from a Random Forest?

3. Explain the advantages of Random Forest?

4. Explain the drawbacks in Random Forest Usage?

5. Describe some of the precautions to optimize the performance of the Random


Forest?

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

2. Predict the occupation for the following dataset

Recency: 3, frequency: 33, monetary: 7900, time: 77


Writing space for the Problem: (For Student’s use only)

36
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

37
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #5: K-Nearest Neighbors Model

Date of the Session: ___/___/___ Time of the Session: _____to______

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.

Now predict for the following data

[158, 28]

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

39
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

41
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

42
17CS3166 MACHINE LEARNING

Viva-voce:
1. What are some applications of KNN?

2. What are the types of distance metrics used in KNN?

3. What is the hamming distance?

4. Why the KNN is called lazy algorithm?

5. Is it case sensitive to outliers?

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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

44
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

45
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #6: Naïve Bayes classification Model

Date of the Session: ___/___/___ Time of the Session: _____to______

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.

2. What are the MAP hypothesis and maximum likelihood?

3. What is Bayes optimal classifier?

4. Why do we use Gibb’s algorithm?

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.

Download the dataset(s) from the repository.

NOTE: DON’T CONSIDER USER ID AS AN INPUT


Writing space for the Problem: (For Student’s use only)

47
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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.

a. Find the accuracy


b. Predict the occupation for the following dataset
Recency: 3, frequency: 33, monetary: 7900, time: 78
Writing space for the Problem: (For Student’s use only)

49
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

50
17CS3166 MACHINE LEARNING

Viva-voce:

1. What is Posterior Probability [P(H/X)]?

2. What is Prior probability [p(H)]?

3. Explain the formula for Bayes Theorem?

4. What are the components in Bayesian Belief Network?

5. Explain Conditional probability?

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:

P (H=T) = 0.001 P (B=T) =0.002

P (H=F) = 0.999 P (B=F) =0.998

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

Compute the probability for the following conditions


P (p1, p2, A, H, B)

P (p1, p2, A, ~H, ~B)

53
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

54
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

55
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

56
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #7: K-Means Clustering Model

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

2. What are the different types of clustering?

3. What is soft clustering and hard clustering?

4. What the centroid represents?

5. What are the pros and cons of K-means 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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

58
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

60
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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?

4. Can we choose a particular k which is best for clustering?

5. What are the steps needed in performing k-means clustering?

6. What is meant by least mean square error

62
17CS3166 MACHINE LEARNING

Post-Lab Task:
1. Write an algorithm for K-means++?

63
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

64
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #8: Hierarchical clustering Model

Date of the Session: ___/___/___ Time of the Session: _____to______

References:
1. https://www.thelearningmachine.ai/hierarchical

2. https://www.datanovia.com/en/lessons/agglomerative-hierarchical-clustering/

Pre-Lab Task:

1. What is hierarchical clustering?

2. What are the different types of hierarchical clustering?

3. What are the uses of the dendrogram graph in hierarchical clustering?

4. List some applications of hierarchical clustering.

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.

Download the dataset(s) from the repository.

Writing space for the Problem: (For Student’s use only)

66
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

68
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

69
17CS3166 MACHINE LEARNING

Viva-voce:
1. What are the different types of hierarchical clustering algorithms.

2. Explain the agglomerative clustering algorithm.

3. Distinguish between agglomerative and divisive clustering algorithms.

4. What is the need of distance measure in the hierarchical clustering algorithm.

5. List out the pros and cons of hierarchical clustering algorithms.

70
17CS3166 MACHINE LEARNING

Post-Lab Task:
1. Discuss in brief about decisive clustering.

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

71
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #9: Support Vector Machine Model

Date of the Session: ___/___/___ Time of the Session: _____to______

References:
1. https://medium.com/machine-learning-101/chapter-2-svm-support-vector-machine-
theory-f0812effc72

Pre-Lab Task:
1. What is SVM?

2. What is the basic principle of hyper plane?

3. How do we select the most optimum hyper plane?

4. In case of non linear data what does SVM do?

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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

73
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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.

a. Find the accuracy

b. Predict cancelled flights based on the given factors

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

Writing space for the Problem: (For Student’s use only)

76
17CS3166 MACHINE LEARNING

Viva-voce:
1. What is generalization error in terms of the SVM?

2. What is hard margin?

3. The effectiveness of an SVM depends upon?

4. What are the real world applications of 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)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

78
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #10: Artificial Neural Network Model - I

Date of the Session: ___/___/___ Time of the Session: _____to______

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]

INPUT1 INPUT2 INPUT3 OUTPUT

0 0 1 0

0 1 1 1

1 0 1 1

1 1 1 0

79
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

80
17CS3166 MACHINE LEARNING

Viva-voce:
1. What is CNN? Explain it with an application.

2. What are the two types of modules in ANN?

3. Define Sequential neural network.

4. Define dense neural network.

5. Which library should be imported while working with ANN?

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].

Writing space for the Problem: (For Student’s use only)

82
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

83
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

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

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

86
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #11: Artificial Neural Network Model - II

Date of the Session: ___/___/___ Time of the Session :_____to______

References:
1. https://towardsdatascience.com/nns-aynk-c34efe37f15a

Pre-Lab Task:
1. What is Deep learning?

2. Distinguish between machine learning and deep learning?

3. Can neural network handle large amount of data?

4. What is activation function?

5. What is back propagation in neural networks?

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.

Download the dataset(s) from the repository.


Writing space for the Problem: (For Student’s use only)

88
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

89
17CS3166 MACHINE LEARNING

Viva-voce:
1. List some commercial practical applications of Artificial Neural Networks.

2. What are the applications of deep learning?

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?

4. How human Brain works?

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

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

92
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #12: Using TensorFlow Model for implementing


Neural Network

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

2. What is gradient descent and what it is used for?

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

Writing space for the Problem: (For Student’s use only)

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?

3) What are deep learning frameworks or tools?

4) What are applications of deep learning in Natural language processing?

5) What are the disadvantages of deep learning?

96
17CS3166 MACHINE LEARNING

Post-Lab Task:
1) Display how many images are used for training?

2) Display how many images are used for testing?

3) Display the 1000th image present in the training data?

4) How to run a variable write a simple code using TensorFlow?

97
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

98
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #13: Developing GUI application using Tkinter


package

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

4. Create a simple canvas window with Green background color.

5. Which tkinter widget is used to take input from the user?

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.

Writing space for the Problem: (For Student’s use only)

100
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

101
17CS3166 MACHINE LEARNING

Viva-voce:
1. What is GUI, how is it used in our University?

2. What are the different ways of developing GUIs in Python3?

3. What is Tkinter?

4. What are widgets? Explain any two of them in brief.

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

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

104
17CS3166 MACHINE LEARNING

LAB EXPERIMENT #14:Develop a solution for Knapsack problem using


Genetic Algorithm

Date of the Session: ___/___/___ Time of the Session: _____to______

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?

2. What is genotype and phenotype?

3. What are the genetic operators?

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:

a. Pocketknife 10.00 1.00

b. Beans 20.00 5.00

c. Sleeping bag 30.00 7.00

d. Rope 10.00 5.00

e. Compass 30.00 1.00


Writing space for the Problem: (For Student’s use only)

106
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

107
17CS3166 MACHINE LEARNING

Viva-voce:
1. What is evolutionary computing?

2. What are different genetic operators?

3. What is genetic programming?

4. What is a chromosome?

5. What is elitism in Genetic Algorithms?

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

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

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

Koneru Lakshmaiah Education foundation


(KL DEEMED TO BE UNIVERSITY)
17CS3166 – Skill – Machine Learning

REGISTER NO : NAME: YEAR / SEM / SECTION


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

Creation of data set using


1
Pandas

Data Manipulation using


2
Numpy

Constructing a linear regression


3
model

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

Constructing Decision Tree


4
model

5 Naïve Bayes Classification

Basic operations on
6
TensorFlow

7 Regression using TensorFlow

Logistic Regression using


8
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

K – Means Clustering using


9
TensorfFow

10 Basic Operations using Opencv

Image Processing using


11
Opencv

12 Video capturing using Opencv

vi
17CS3166 MACHINE LEARNING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 17CS3166
MACHINE LEARNING

Exercise #1: Creation of data set using Pandas


Date of the Session: ___/___/___
Time of the Session: _____to______
Based on the following queries write a python code in jupyter note book

A) INTRODUCTION TO PANDAS

1. Use series method to convert the following list[‘a’,’b’,’c’,’d’]


2. Given the lists which contain names of students and their scored marks you
have to create data frames which club them all using pandas. student list is
['praharsha' ,'mythresh', 'kowshik' ,'pranay', 'srujan' 'raju'] and you are given
a 2d matrix which contain their marks. Their marks are [[77,89,92,95],
[85,94,97,76], [77,88,99,74], [90,89,92,78], [83,97,80,98],[90,90,80,87]] and
subjects list containing ['bio','phy','che', 'mat']
3. Add the sci , total columns to the data frame from which science is the sum
of phy, che and bio and total is the sum of all subjects?
4. Display only the marks scored by praharsha and srujan?
5. Display all the students marks who scored 90 + marks in physics?
6. Biology teacher wants to know the total marks achieved by students in
biology, Help her by using the sum method in data frame?

B) EXCEL SHEET HANDLING

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

Writing space for the Problem: (For Student’s use only)

2
17CS3166 MACHINE LEARNING

Writing space for the Problem: (For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

3
17CS3166 MACHINE LEARNING

Exercise #2: Data Manipulation using Numpy


Date of the Session: ___/___/___
Time of the Session: _____to______

1) Write a program of a two-dimensional array using numpy and print


elements, reverse the rows of the 2D array and print the elements?
2) Generate the digits up to 15 using the np.arange method?
3) Print the common items from and hu two Numpy arrays and also print the
position of the common elements and remove the common items and print
the different elements also of two Numpy arrays?
4) Write a numpy program to generate the 10 random integers between 10 and
100.
5) Generate a random 4*4 matrix of integers ranging from 0 to to to to 100 by
using numpy and also to use in the nd minimum values?
6) Divide all digits from 1 to 10010011 using linspace method?
7) Find the default plot size in matplotlib plots, print the default size and
change the plot size to [10,10] by using the matplotlib library.
8) Create a line plot for the given equation y=x^3 and plot some points using
linspace() in the range (-10,10) and also label x-axis, y-axis and give the
title of graph cubic function and display the graph
9) Represent a graph by using subplot as two rows and two columns and fill all
the positions by plotting y=x^2 and display the graph.
10) Represent two equations & in one graph and use Legend
function.

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.

15) Do the following:

i) From the above data, Identify all the points of X, Y as co-ordinates by


using Scatter 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

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

12
17CS3166 MACHINE LEARNING

Exercise #3: Constructing a linear regression

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

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

15
17CS3166 MACHINE LEARNING

Exercise #4: Constructing Decision Tree


model
Date of the Session: ___/___/___
Time of the Session: _____to______

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.

download data from https://drive.google.com/file/d/1PQ_ay-


Kd7Yj6e3vXsKgsv9AGKP4nRX0r/view?usp=sharing

16
17CS3166 MACHINE LEARNING

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

17
17CS3166 MACHINE LEARNING

Exercise #5: Naïve Bayes Classification

Date of the Session: ___/___/___


Time of the Session: _____to______

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

download the link from


https://drive.google.com/file/d/1hXnKRrs5hmaTYp4D5jOWpK8pEktlbjF-
/view?usp=sharing

18
17CS3166 MACHINE LEARNING

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

19
17CS3166 MACHINE LEARNING

Exercise #6: Basic operations on TensorFlow

Date of the Session: ___/___/___


Time of the Session: _____to______

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

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

23
17CS3166 MACHINE LEARNING

Exercise #7: Regression using TensorFlow

Date of the Session: ___/___/___


Time of the Session: _____to______

Create a dataset of 100000 using line space and generate noise of size 100000
using np.random.randn

Consider the line y=0.5*x+5

With the x values,generate y values and add noise to the y values.

Create data frame and concatenate it.

Plot the data points.

After predicting the values check the error using reduce.sum.

And optimize the error using gradient descent optimizer.

Create and run the session and plot the respective line.4

take the following values as input for building a model

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

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

26
17CS3166 MACHINE LEARNING

Exercise #8: Logistic Regression using


TensorFlow
Date of the Session: ___/___/___
Time of the Session: _____to______

From tensorflow. examples. tutorials. mnist import the input data.

Learning rate=0.01

Training epochs=25

Batch size=100

Display step=1

Use softmax and matmul to predict the output using the matrices.

Calculate the error using reduce_mean.

Optimize the error using gradient descent optimizer.

Create and run the session using logistic regression.

Calculate the accuracy using accuracy.eval.

27
17CS3166 MACHINE LEARNING

28
17CS3166 MACHINE LEARNING

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

29
17CS3166 MACHINE LEARNING

Exercise #9: K – Means Clustering using


TensorFlow
Date of the Session: ___/___/___
Time of the Session: _____to______

From tensorflow. examples. tutorials. mnist import the input data.

num_steps = 50 # Total steps to train

batch_size = 1024 # The number of samples per batch

k = 25 # The number of clusters

num_classes = 10 # The 10 digits

num_features = 784 # Each image is 28x28 pixels

create and run the session.

Using the above features perform K-Means clustering.

30
17CS3166 MACHINE LEARNING

31
17CS3166 MACHINE LEARNING

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

32
17CS3166 MACHINE LEARNING

Exercise #10: Basic Operations using Opencv

Date of the Session: ___/___/___


Time of the Session: _____to______

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

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

35
17CS3166 MACHINE LEARNING

Exercise #11: Image Processing using Opencv

Date of the Session: ___/___/___


Time of the Session: _____to______

1)load an image and apply some filters named hsv image,hue


channel,saturation,value channel and display all of them(Hint:use 0 for hue
channel ,1 for saturation and 2 for value channel)

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

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

39
17CS3166 MACHINE LEARNING

Exercise #12: Video capturing using Opencv

Date of the Session: ___/___/___


Time of the Session: _____to______
SKILL-12

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

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

43

You might also like