0% found this document useful (0 votes)
147 views70 pages

Applied Machine Learning Lab Manual

The document is a laboratory manual for the Applied Machine Learning course, designed to enhance students' practical skills and competencies in machine learning. It outlines course objectives, industry-relevant skills, guidelines for faculty and students, and includes detailed experiments with implementation instructions. The manual emphasizes a hands-on approach to learning, ensuring students are prepared for real-world applications of machine learning concepts.

Uploaded by

mananvadher3385
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)
147 views70 pages

Applied Machine Learning Lab Manual

The document is a laboratory manual for the Applied Machine Learning course, designed to enhance students' practical skills and competencies in machine learning. It outlines course objectives, industry-relevant skills, guidelines for faculty and students, and includes detailed experiments with implementation instructions. The manual emphasizes a hands-on approach to learning, ensuring students are prepared for real-world applications of machine learning concepts.

Uploaded by

mananvadher3385
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

A Laboratory Manual for

Applied Machine Learning


(3171617)

B.E. Semester 7
(Information Technology)

Directorate of Technical Education, Gandhinagar,


Gujarat
Government Engineering College, Modasa

Certificate

This is to certify that Mr./Ms. __________________________ Enrollment No.


_________________________ of B.E. Semester ____ Information Technology of
this Institute (GTU Code: 016) has satisfactorily completed the Practical /
Tutorial work for the subject Applied Machine Learning (3171617) for
the academic year 2023-24.

Date:

Name and Sign of Faculty member

Head of the Department

2
Applied Machine Learning (3171617)

Preface

Main motto of any laboratory/practical/field work is for enhancing required skills as well
as creating ability amongst students to solve real time problem by developing relevant
competencies in psychomotor domain. By keeping in view, GTU has designed competency
focused outcome-based curriculum for engineering degree programs where sufficient
weightage is given to practical work. It shows importance of enhancement of skills amongst
the students and it pays attention to utilize every second of time allotted for practical
amongst students, instructors and faculty members to achieve relevant outcomes by
performing the experiments rather than having merely study type experiments. It is must
for effective implementation of competency focused outcome-based curriculum that every
practical is keenly designed to serve as a tool to develop and enhance relevant competency
required by the various industry among every student. These psychomotor skills are very
difficult to develop through traditional chalk and board content delivery method in the
classroom. Accordingly, this lab manual is designed to focus on the industry defined
relevant outcomes, rather than old practice of conducting practical to prove concept and
theory.

By using this lab manual students can go through the relevant theory and procedure in
advance before the actual performance which creates an interest and students can have
basic idea prior to performance. This in turn enhances pre-determined outcomes amongst
students. Each experiment in this manual begins with competency, industry relevant skills,
course outcomes as well as practical outcomes (objectives). The students will also achieve
safety and necessary precautions to be taken while performing practical.

This manual also provides guidelines to faculty members to facilitate student centric lab
activities through each experiment by arranging and managing necessary resources in
order that the students follow the procedures with required safety and necessary
precautions to achieve the outcomes. It also gives an idea that how students will beassessed
by providing rubrics.

Engineering Thermodynamics is the fundamental course which deals with various forms
of energy and their conversion from one to the another. It provides a platform for students
to demonstrate first and second laws of thermodynamics, entropy principle and concept
of exergy. Students also learn various gas and vapor power cycles and refrigeration cycle.
Fundamentals of combustion are also learnt.

Utmost care has been taken while preparing this lab manual however always there is
chances of improvement. Therefore, we welcome constructive suggestions forimprovement
and removal of errors if any.

3
Applied Machine Learning (3171617)

Practical – Course Outcome matrix

Course Outcomes (COs):


1. Explore the fundamental issues and challenges in Machine Learning including data
and model selection and complexity
2. Appreciate the underlying mathematical relationships within and across Machine
Learning algorithms
3. Evaluate the various Supervised and Unsupervised Learning algorithms using
appropriate Dataset
4. Design and evaluate Deep learning Algorithms
5. Design and implement various machine learning algorithms in a range of real-
world applications

Sr. CO CO CO CO CO
Objective(s) of Experiment
No. 1 2 3 4 5
Statistical measures such as Mean, Median and
1. √ √
Mode of the data.

2. Probability Distributions. √ √

3. Implement Bayes Theorem model. √ √

4. Linear Regression Model √ √

5. Logistics Regression Model √ √

6. K-NN classifier √ √

7. Clustering Model √ √

8. Neural Network √ √

9. Deep Neural Network √ √

10. Convolutional Neural Network √ √

4
Applied Machine Learning (3171617)

Industry Relevant Skills

The following industry relevant competency are expected to be developed in the


student by undertaking the practical work of this laboratory.
1. Apply knowledge of Applied Machine Learning to solve real world problems
2. Understand and analyze the data analytically to use them wisely to build the ML
model.
3. Utilize deep learning models to solve societal problems.

Guidelines for Faculty members


1. Faculty should provide the guideline with demonstration of practical to the
students with all features.
2. Faculty shall explain basic concepts/theory related to the experiment to the
students before starting of each practical
3. Involve all the students in performance of each experiment.
4. Faculty is expected to share the skills and competencies to be developed in the
students and ensure that the respective skills and competencies are developed in
the students after the completion of the experimentation.
5. Faculty should give opportunity to students for hands-on experience after the
demonstration.
6. Faculty may provide additional knowledge and skills to the students even
though not covered in the manual but are expected from the students by
concerned industry.
7. Give practical assignment and assess the performance of students based on task
assigned to check whether it is as per the instructions or not.
8. Faculty is expected to refer complete curriculum of the course and follow the
guidelines for implementation.
9. Faculty is expected to share common dataset to students for various
experiments.

Instructions for Students


1. Students are expected to carefully listen to all the theory classes delivered by the
faculty members and understand the COs, content of the course, teaching and
examination scheme, skill set to be developed etc.
2. Students shall organize the work in the group and make record of all observations.
3. Students shall develop maintenance skill as expected by industries.
4. Student shall attempt to develop related hand-on skills and build confidence.
5. Student shall develop the habits of evolving more ideas, innovations, skills etc. apart
from those included in scope of manual.
6. Student shall refer technical magazines and data books.
5
7. Student should develop a habit of submitting the experimentation work as per the
schedule and s/he should be well prepared for the same.

6
Index
(Progressive Assessment Sheet)

Sr. No. Objective(s) of Page Date of Date of Assessment Sign. of Remarks


Experiment No. performance submission Marks Teacher
with date
1 Statistical measures such as Mean, 8
Median and Mode ofthe data
2 Probability Distributions 13

3 Implement Bayes Theorem model 22

4 Linear Regression Model 26

5 Logistics Regression Model 32

6 K-NN classifier 38

7 Clustering Model 44

8 Neural Network 50

9 Deep Neural Network 57

10 Convolutional Neural 64
Network

Total

7
Applied Machine Learning (3171617)

Experiment No 1 : Statistical measures such as Mean, Median and Mode of


the data

Date:

Competency and Practical Skills:

Relevant CO: 1, 2

Objectives:

1. To understand basic statistical properties of data like mean, median and mode

2. To learn about effect of outliers on these properties

Implementation:

1. Write a program to compute mean, median and mode for given data using preferred
programming language.

2. Plot the histogram for the data and show mean, median and mode in the histogram.

Source Code with Output:

Implementation 1:

Program:
import statistics

def calculate_mean(data):
return [Link](data)

def calculate_median(data):
return [Link](data)

def calculate_mode(data):
try:
return [Link](data)
except [Link]:
return "No unique mode found"

if __name__ == "__main__":
data = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9]

mean = calculate_mean(data)
median = calculate_median(data)
mode = calculate_mode(data)

print(f"Data: {data}")
8
print(f"Mean: {mean}")
print(f"Median: {median}")
print(f"Mode: {mode}")

Output:

Implementation 2:

Program:
import statistics
import [Link] as plt

def calculate_mean(data):
return [Link](data)

def calculate_median(data):
return [Link](data)

def calculate_mode(data):
try:
return [Link](data)
except [Link]:
return None

data = [1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9]

mean = calculate_mean(data)
median = calculate_median(data)
mode = calculate_mode(data)

[Link](data, bins=10, alpha=0.75, color='b', edgecolor='k')

[Link](mean, color='r', linestyle='dashed', linewidth=2, label=f"Mean = {mean:.2f}")


[Link](median, color='g', linestyle='dashed', linewidth=2, label=f"Median = {median}")
if mode is not None:
[Link](mode, color='y', linestyle='dashed', linewidth=2, label=f"Mode = {mode}")

[Link]('Value')
[Link]('Frequency')
[Link]()
[Link]('Histogram with Mean, Median, and Mode')
[Link]()

9
Output:

Conclusion:

In practice, the choice of which measure to use depends on the nature of the data and the specific goals
of the analysis. Mean is appropriate for symmetrical, normally distributed data with minimal outliers. Median
is preferred when data is skewed or contains outliers, as it is more robust. Mode is useful for identifying the
most common value or category within a dataset.

In summary, Mean, Median, and Mode are indispensable statistical measures that provide valuable
insights into the central tendencies of data. Careful consideration of the data's characteristics and potential
outliers is essential when choosing the most appropriate measure for a given analysis. These measures, in
combination with other statistical techniques, help researchers and analysts make informed decisions and
draw meaningful conclusions from their data.

Related Questions:

1. What is the difference between mean and median?


Mean Median
➢ The mean is the arithmetic average of a set ➢ The median is described as the numeric
of numbers, or distribution. It is the most value separating the higher half of a
commonly used measure of central sample, a population, or a probability
tendency of a set of numbers. distribution, from the lower half.
➢ The mean is used for normal distributions. ➢ The median is generally used for skewed
distributions.
➢ The mean is not a robust tool since it is ➢ The median is better suited for skewed
largely influenced by outliers. distributions to derive at central tendency
since it is much more robust and sensible.
➢ A mean is computed by adding up all the ➢ The Median is the number found at the exact
values and dividing that score by the middle of the set of values. A median can be
number of values. computed by listing all numbers in ascending
10
order and then locating the number in the
centre of that distribution.

2. Which measure of central tendency is preferred when the data set has extreme values?

➢ When a dataset contains extreme values or outliers, the median is typically preferred as the
measure of central tendency. Here's why:

1. Robustness to Outliers: The median is robust to outliers, meaning that extreme values do not
unduly influence its value. It is resistant to the effects of outliers, as it depends solely on the position
of values within the dataset. Outliers might be far from the median, but they won't affect its value.

2. Reflects the Center of the Data: The median represents the middle value when the dataset is sorted,
making it a better indicator of the center of the data, especially when outliers are present. It divides
the dataset into two equal halves, with 50% of the values falling above and 50% falling below it.

3. Use in Skewed Distributions: In datasets with skewed distributions, where the majority of data
points are concentrated on one side, the mean can be heavily skewed by outliers. The median, on the
other hand, remains a stable representation of the typical value.

4. Common Practice: It is a common practice to use the median in statistical analysis when dealing
with data that may contain outliers. This helps to prevent the distortion of central tendency measures
caused by extreme values.

However, it's important to note that the choice between the mean and median ultimately depends on
the specific goals of the analysis, the nature of the data, and the presence of outliers. In some cases,
you may choose to analyze both the mean and median to gain a comprehensive understanding of the
dataset.

11
Applied Machine Learning (3171617)

Suggested Reference:

• [Link]
mode-and-range

• [Link]
definitions/mean-median-mode/

• [Link]

References used by the students:

[Link]

[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

12
Applied Machine Learning (3171617)

Experiment No: 2 Probability Distributions

Date:

Competency and Practical Skills:

Relevant CO: 1, 2

Objectives:

1. To understand different probability distributions such as the normal distribution,


Poisson distribution, or Bernoulli distribution

2. To learn about model a dataset as per requirements.

Implementation:

1. Implement probability distributions such as the normal distribution, Poisson


distribution, or Bernoulli distribution using Python.

2. Generate random samples from the distributions and visualize the results using
Matplotlib.

3. Use the distributions to model a dataset of your choice

Source Code with Output:

Implementation 1:

Normal Distribution:
Program:
import numpy as np
from [Link] import norm
import [Link] as plt

mean = 0
std_dev = 1
size = 1000

# Generate random samples from a normal distribution


data = [Link](mean, std_dev, size)

# Plot a histogram of the generated data


[Link](data, bins=30, density=True, alpha=0.6, color='g')

# Calculate the probability density function (PDF)


x = [Link](-3, 3, 100)
pdf = [Link](x, mean, std_dev)
[Link](x, pdf, 'r-', lw=2, label='PDF')

13
[Link]('Normal Distribution')
[Link]()
[Link]()
Output:

Poisson Distribution:
Program:
from [Link] import poisson

rate = 3 # Average number of events in the interval


size = 1000

# Generate random samples from a Poisson distribution


data = [Link](mu=rate, size=size)

# Calculate the probability mass function (PMF)


x = range(0, 15)
pmf = [Link](x, mu=rate)

print(data)
Output:

14
Bernoulli Distribution:
Program:

import numpy as np

p = 0.3 # Probability of success


size = 1000

# Generate random samples from a Bernoulli distribution


data = [Link]([0, 1], size=size, p=[1 - p, p])

print(data)
Output:

Implementation 2:

Normal Distribution:
Program:

import numpy as np
import [Link] as plt
from [Link] import norm

mean = 0
std_dev = 1
size = 1000

# Generate random samples from a normal distribution


data = [Link](mean, std_dev, size)

# Create a histogram to visualize the data


[Link](data, bins=30, density=True, alpha=0.6, color='g')

# Calculate and plot the probability density function (PDF)


x = [Link](-3, 3, 100)
pdf = [Link](x, mean, std_dev)
[Link](x, pdf, 'r-', lw=2, label='PDF')

[Link]('Normal Distribution')
[Link]()
15
[Link]()

Output:

Poisson Distribution:

Program:
import numpy as np
import [Link] as plt
from [Link] import poisson

rate = 3 # Average number of events in the interval


size = 1000

# Generate random samples from a Poisson distribution


data = [Link](mu=rate, size=size)

# Create a histogram to visualize the data


[Link](data, bins=15, density=True, alpha=0.6, color='b')

# Calculate and plot the probability mass function (PMF)


x = range(0, 15)
pmf = [Link](x, mu=rate)
[Link](x, 0, pmf, colors='r', lw=2, label='PMF')

[Link]('Poisson Distribution')
[Link]()
[Link]()

16
Output:

Bernoulli Distribution:
Program:
import numpy as np
import [Link] as plt

p = 0.3 # Probability of success


size = 1000

# Generate random samples from a Bernoulli distribution


data = [Link]([0, 1], size=size, p=[1 - p, p])

# Create a bar chart to visualize the data


unique, counts = [Link](data, return_counts=True)
[Link](unique, counts, tick_label=[0, 1], alpha=0.6, color='y')

[Link]('Bernoulli Distribution')
[Link]()
Output:

17
Implementation 3:
Program:
import numpy as np
import [Link] as plt
from [Link] import norm

# Define the parameters for the normal distribution


mean = 75 # Mean exam score
std_dev = 10 # Standard deviation

# Generate random exam scores for a class of 200 students


num_students = 200
exam_scores = [Link](mean, std_dev, num_students)

# Create a histogram to visualize the distribution of exam scores


[Link](exam_scores, bins=20, density=True, alpha=0.6, color='b')

# Calculate and plot the probability density function (PDF)


x = [Link](40, 110, 100)
pdf = [Link](x, mean, std_dev)
[Link](x, pdf, 'r-', lw=2, label='PDF')

[Link]('Distribution of Exam Scores')


[Link]('Exam Score')
[Link]('Frequency')
[Link]()
[Link]()
Output:

Conclusion:
These probability distributions and their respective Python libraries provide essential tools for
modeling, simulating, and analyzing various random processes and events in both scientific and
engineering domains. Understanding the characteristics and appropriate use cases for each distribution is
crucial in conducting experiments and drawing meaningful conclusions from data.

18
Related Questions:

1. What is Random Variables?


A random variable is a fundamental concept in probability theory and statistics. It represents a
numerical outcome or value that results from a random experiment, process, or event. In other
words, a random variable is a variable whose value is subject to chance or randomness. Random
variables are used to model and quantify uncertainty in various situations.

There are two main types of random variables:

1. Discrete Random Variable:


- A discrete random variable can take on a countable set of distinct values.
- It is often associated with events that can be counted or enumerated.
- Example: The number of heads obtained when flipping a fair coin multiple times. The possible
values are 0, 1, 2, and so on.

2. Continuous Random Variable:


- A continuous random variable can take on an uncountably infinite number of values within a
specified range.
- It is associated with measurements or quantities that can have an infinite number of values.
- Example: The height of individuals in a population. Heights can be any value within a range, and
there are infinitely many possible values.

Random variables can be further categorized as:

- Univariate: Involving a single random variable.


- Multivariate: Involving multiple random variables that are often interrelated.

Random variables are used to describe and analyze probabilistic events and phenomena. They
allow us to define probability distributions that specify the likelihood of different outcomes and
enable the calculation of various statistical measures and properties, such as expected values,
variances, and probabilities.

In mathematical notation, random variables are often represented by capital letters (e.g., X, Y) and
are associated with probability functions or probability density functions that describe the
probabilities of different values or ranges of values for the random variable. Random variables are
a foundational concept in statistics and probability and are used in a wide range of applications,
including risk assessment, statistical modeling, and data analysis.

2. What is the difference normal distribution, Poisson distribution, and Bernoulli


distribution?

Normal distribution, Poisson distribution, and Bernoulli distribution are all fundamental probability
distributions used to model different types of random variables in statistics and probability theory.
Here are the key differences between these distributions:

1. Normal Distribution (Gaussian Distribution):


- Shape: The normal distribution is a continuous probability distribution that has a symmetric bell-
shaped curve. It is characterized by its probability density function (PDF), which is bell-shaped and
19
centered at the mean.
- Use:The normal distribution is commonly used to model real-world phenomena where the data is
approximately normally distributed. It is used for continuous variables, such as heights, weights, and
measurement errors.
- Parameters: It is defined by two parameters, the mean (μ) and the standard deviation (σ), which
determine the center and the spread of the distribution.
- Notable Properties: The normal distribution is characterized by the 68-95-99.7 rule, also known as
the empirical rule, which states that approximately 68% of the data falls within one standard
deviation of the mean, 95% within two standard deviations, and 99.7% within three standard
deviations.

2. Poisson Distribution:
- Shape: The Poisson distribution is a discrete probability distribution that models the number of
events that occur within a fixed interval of time or space. It is characterized by a probability mass
function (PMF) that describes the probabilities of different counts.
-Use: The Poisson distribution is used to model rare events or count data, such as the number of
phone calls at a call center in an hour or the number of emails received in a day.
- Parameter: It is defined by a single parameter, λ (lambda), which represents the average rate at
which events occur.
- Notable Properties: The Poisson distribution is memoryless, meaning that the probability of an
event occurring in the future is not influenced by the past.

3. Bernoulli Distribution:
- Shape: The Bernoulli distribution is the simplest discrete probability distribution. It models a
binary outcome, where there are only two possible results (success and failure).
- Use: The Bernoulli distribution is used to model binary events, such as the outcome of a coin flip
(heads or tails), the success or failure of a single trial, or a yes/no outcome.
- Parameter: It is defined by a single parameter, p, which represents the probability of success (e.g.,
the probability of getting a "heads" in a coin toss).
- Notable Properties:The Bernoulli distribution can be considered as a special case of the binomial
distribution when the number of trials is 1. The mean of the Bernoulli distribution is equal to p, and
the variance is p(1-p).

In summary, the main differences between these distributions lie in their shapes, the types of data
they model, and the number of parameters required to define them. The normal distribution is
continuous and used for modeling continuous data, while the Poisson and Bernoulli distributions are
discrete and are used for modeling count and binary data, respectively.

20
Applied Machine Learning (3171617)

Suggested Reference:

• [Link]
statistical-methods/statistical-distributions

• [Link]

• [Link]

References used by the students:


[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

21
Experiment No 3: Implement Bayes Theorem model

Date:

Competency and Practical Skills:

Relevant CO: 2, 5

Objectives:

1. To understand working of Bayes theorem.

2. To implement and test bayes theorem model.

Implementation:

For a medical testing company, and your company has developed a new test for a disease that
affects 1 in every 1,000 people. The test is very accurate, with a false positive rate of only 1%
(meaning that it correctly identifies 99% of people who don't have the disease) and a false
negative rate of 5% (meaning that it correctly identifies 95% of people who do have the
disease).

A patient comes to your company for testing, and the test comes back positive. What is the
probability that the patient actually has the disease using bayes rules?

Note: Add comments in the program at the appropriate location.

Source Code with Output:

Implementation:
Program:
# Define the probabilities
p_disease = 0.001 # Probability of having the disease
p_no_disease = 1 - p_disease # Probability of not having the disease
p_positive_given_disease = 0.95 # Probability of a positive test result given the disease
p_positive_given_no_disease = 0.01 # Probability of a positive test result given no disease

# Calculate the probability of a positive test result using the law of total probability
p_positive = (p_positive_given_disease * p_disease) + (p_positive_given_no_disease *
p_no_disease)

# Calculate the probability of having the disease given a positive test result using Bayes'
theorem
p_disease_given_positive = (p_positive_given_disease * p_disease) / p_positive

# Print the result


print(f"The probability that the patient actually has the disease given a positive test result is:
{p_disease_given_positive:.4f}")

22
Output:

Conclusion:

In conclusion, implementing a Bayes Theorem model is a powerful and versatile approach in the
field of statistics and probability theory. Bayes' theorem allows us to update our beliefs and make
informed decisions in the presence of uncertainty, making it a fundamental tool in various
applications, including machine learning, medical diagnosis, spam filtering, and more.

The model leverages conditional probability to compute the probability of an event occurring
based on prior knowledge and new evidence. By formalizing the relationship between prior beliefs,
likelihood, and posterior probabilities, Bayes' theorem provides a structured framework for
reasoning and inference.

Related Questions:

1. What is Bayes theorem?


Bayes' theorem, also known as Bayes' rule or Bayes' law, is a fundamental concept in
probability theory and statistics. It describes how to update or revise the probability for a
hypothesis or event in light of new evidence. Bayes' theorem is named after the Reverend Thomas
Bayes, an 18th-century British mathematician and theologian.

The theorem itself is expressed as follows:

𝐴 𝐵
𝑝 ( ) = 𝑃 ( ) . 𝑝(𝐴)/𝑃(𝐵)
𝐵 𝐴

Where:
- P(A|B)is the posterior probability of event or hypothesis A given evidence B.
- P(B|A)is the probability of observing evidence B given that event A has occurred. This is called
the likelihood.
- P(A)is the prior probability of event A, which is our initial belief or probability before considering
the evidence.
- P(B) the total probability of observing evidence B.

In essence, Bayes' theorem provides a structured way to update our beliefs (the prior probability)
about an event or hypothesis based on observed evidence. It is particularly valuable in scenarios
with uncertainty and incomplete information.

Applications of Bayes' theorem include:


- Bayesian inference: Updating beliefs about model parameters in statistics.
- Bayesian classification: In machine learning, where it's used for spam filtering, sentiment
analysis, and more.
23
- Medical diagnosis: Combining prior medical knowledge with test results to make a diagnosis.
- A/B testing: Evaluating the impact of changes or interventions in experiments.
- Natural language processing: Bayesian methods are used in language models and part-of-speech
tagging.
- Image and speech recognition: Bayesian approaches are employed in various pattern recognition
tasks.

Bayes' theorem is a foundational concept in probability and statistics, and it provides a principled
way to incorporate new evidence into our understanding of the world and make informed
decisions in the presence of uncertainty.

2. What is conditional probability?

Conditional probability is known as the possibility of an event or outcome happening, based on the
existence of a previous event or outcome. It is calculated by multiplying the probability of the preceding
event by the renewed probability of the succeeding, or conditional, event.

Here the concept of the independent event and dependent event occurs. Imagine a student who takes
leave from school twice a week, excluding Sunday. If it is known that he will be absent from school on
Tuesday then what are the chances that he will also take a leave on Saturday in the same week? It is
observed that in problems where the occurrence of one event affects the happening of the following event,
these cases of probability are known as conditional probability

. P(A|B) = N(A∩B)/N(B)

Or
P(B|A) = N(A∩B)/N(A)

Suggested Reference:

• [Link]

• [Link]

24
References used by the students:

[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

25
Experiment No 4: Linear Regression Model

Date:

Competency and Practical Skills:

Relevant CO: 3, 5

Objectives:

1. To understand how linear regression works

2. To learn the applications of linear regression

3. To implement and test the linear regression model

Implementation:

1. Implement a simple linear regression model.

2. Train the model using a given dataset.

3. Evaluate the performance of the model using the mean squared error and R-squared
metrics.

Note: Add comments in the program at the appropriate location.

Source Code with Output:

Implementation 1:
Program:
import numpy as np
import [Link] as plt

# Generate synthetic data


[Link](0)
X = 2 * [Link](100, 1)
y = 4 + 3 * X + [Link](100, 1)

# Plot the synthetic data


[Link](X, y, alpha=0.6)
[Link]("Input (X)")
[Link]("Output (y)")
[Link]("Synthetic Data for Linear Regression")
[Link]()

# Linear regression model


X_b = np.c_[[Link]((100, 1)), X] # Add a bias term (intercept)
theta_best = [Link](X_b.[Link](X_b)).dot(X_b.T).dot(y)

# Print the model parameters (intercept and slope)


print("Intercept (theta0):", theta_best[0])
26
print("Slope (theta1):", theta_best[1])

# Make predictions
X_new = [Link]([[0], [2]])
X_new_b = np.c_[[Link]((2, 1)), X_new]
y_predict = X_new_b.dot(theta_best)

# Plot the linear regression model


[Link](X_new, y_predict, "r-", label="Predictions")
[Link](X, y, alpha=0.6, label="Data")
[Link]("Input (X)")
[Link]("Output (y)")
[Link]()
[Link]("Linear Regression Model")
[Link]()
Output:

27
Implementation 2:
Program:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
import [Link] as plt

# Load your dataset from a CSV file


data = pd.read_csv('[Link]')

# Split the dataset into input (X) and output (y)


X = data[[‘dbt’]]
y = data[‘data']

# Split the dataset into a training set and a testing set (e.g., 80% training, 20% testing)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create a linear regression model


model = LinearRegression()

# Train the model on the training data


[Link](X_train, y_train)

# Make predictions on the testing data


y_pred = [Link](X_test)

# Plot the regression line and the testing data


[Link](X_test, y_test, label='Testing Data', alpha=0.6)
[Link](X_test, y_pred, color='red', label='Regression Line')
[Link]('Input (X)')
[Link]('Output (y)')
[Link]('Linear Regression Model')
[Link]()
[Link]()

28
Output:

Implementation 3:
Program:
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from [Link] import mean_squared_error, r2_score

# Load the dataset from a CSV file


data = pd.read_csv('your_dataset.csv')

# Split the dataset into input (X) and output (y)


X = data[['independent_variable_column']]
y = data['dependent_variable_column']

# Split the dataset into a training set and a testing set (e.g., 80% training, 20% testing)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create a linear regression model


model = LinearRegression()

# Train the model on the training data


[Link](X_train, y_train)

# Make predictions on the testing data


y_pred = [Link](X_test)

# Calculate the mean squared error (MSE)


mse = mean_squared_error(y_test, y_pred)

# Calculate the R-squared (R²) score


r2 = r2_score(y_test, y_pred)

29
print(f"Mean Squared Error (MSE): {mse:.2f}")
print(f"R-squared (R²) Score: {r2:.2f}")
Output:

Conclusion:
In conclusion, the linear regression model is a fundamental and widely used technique in statistics
and machine learning. It provides a simple yet powerful framework for understanding and modeling the
relationship between variables.

Related Questions:

1. What is mean squared error and R-squared metrics?


Mean Squared Error (MSE):
- Measures the average squared difference between predicted and actual values in a dataset.
- Lower MSE indicates better predictive accuracy.

R-squared (R²):
- Measures how well a model explains the variance in the dependent variable.
- Ranges from 0 to 1, with higher values indicating a better fit to the data.

In summary, MSE assesses prediction accuracy, while R² assesses model fit and how well it
explains the data.

2. What is multivariate regression?


➢ Multivariate regression is a statistical technique used to model the relationship between a
dependent variable (the outcome we want to predict) and multiple independent variables
(factors that influence the outcome). It extends simple linear regression to accommodate
multiple predictors. The goal is to find the coefficients that best describe this relationship, often
using the least squares method. It is used in various fields to understand and predict complex
phenomena influenced by multiple factors. Model performance is assessed using metrics like R²
and MSE.

Suggested Reference:

• [Link]

• [Link]
learning/

30
References used by the students:

[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

31
Experiment No 5: Logistics Regression Model

Date:

Competency and Practical Skills:

Relevant CO: 3, 5

Objectives:

1. To understand how logistic regression works

2. To learn the applications of logistic regression

3. To implement and test the logistic regression model

Implementation:

1. Implement a logistic regression model using the scikit-learn library.

2. Train the model using a binary classification dataset of your choice.

3. Evaluate the performance of the model using metrics such as accuracy, precision,
recall, and F1-score.

Source Code with Output:

Implementation 1:

Program:
# Import necessary libraries
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from [Link] import accuracy_score, confusion_matrix
import [Link] as plt

# Generate synthetic data


[Link](0)
X = [Link](100, 2) # 100 samples with 2 features
y = [Link]([0, 1], 100) # Binary target variable (0 or 1)

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create a logistic regression model


model = LogisticRegression()

# Train the model on the training data


[Link](X_train, y_train)

# Make predictions on the test data


32
y_pred = [Link](X_test)

# Calculate accuracy and confusion matrix


accuracy = accuracy_score(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)

# Display the results


print("Accuracy:", accuracy)
print("Confusion Matrix:\n", conf_matrix)

# Plot decision boundary


# This part is specific to 2D data and serves for visualization purposes
if X_train.shape[1] == 2:
# Create a mesh grid for the decision boundary
xx, yy = [Link]([Link](X_train[:, 0].min() - 1, X_train[:, 0].max() + 1, 100),
[Link](X_train[:, 1].min() - 1, X_train[:, 1].max() + 1, 100))
Z = [Link](np.c_[[Link](), [Link]()]).reshape([Link])

# Plot the decision boundary and data points


[Link](xx, yy, Z, alpha=0.4)
[Link](X_train[:, 0], X_train[:, 1], c=y_train, marker='o', edgecolor='k')
[Link]("Logistic Regression Decision Boundary")
[Link]("Feature 1")
[Link]("Feature 2")
[Link]()

Output:

33
Implementation 2:

Program:
# Import necessary libraries
from [Link] import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from [Link] import accuracy_score, confusion_matrix

# Load the Breast Cancer dataset


data = pd.read_csv(‘[Link]’)
X = data[[‘dbt’]]
y = data[‘data’]

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# Create a logistic regression model


model = LogisticRegression()

# Train the model on the training data


[Link](X_train, y_train)

# Make predictions on the test data


y_pred = [Link](X_test)

# Calculate accuracy and confusion matrix


accuracy = accuracy_score(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)

# Display the results


print("Accuracy:", accuracy)
print("Confusion Matrix:\n", conf_matrix)

Output:

34
Implementation 3:

Program:
from [Link] import accuracy_score, precision_score, recall_score, f1_score
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from [Link] import accuracy_score, confusion_matrix
import pandas as pd

from prac5imp2 import y_pred

# Load the Breast Cancer dataset


data = pd.read_csv('[Link]')

X = data[['dbt']]
y = data['data']

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)
# Calculate accuracy
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)

# Calculate precision
precision = precision_score(y_test, y_pred)
print("Precision:", precision)

# Calculate recall
recall = recall_score(y_test, y_pred)
print("Recall:", recall)

# Calculate F1-score
f1 = f1_score(y_test, y_pred)
print("F1-Score:", f1)

Output:

Conclusion:
In conclusion, the logistic regression model is a fundamental and widely used technique in the fields of
statistics and machine learning, particularly for binary and multi-class classification tasks.

Related Questions:

1. What are some common performance metrics used to evaluate the


accuracy of alogistic regression model, and how do you interpret them?
➢ Common performance metrics for evaluating a logistic regression model:

35
1. Accuracy: Overall correctness of predictions.

2. Precision: Proportion of true positives among positive predictions.

3. Recall (Sensitivity):Proportion of true positives among actual positives.

4. F1-Score: Harmonic mean of precision and recall.

5. Specificity:Proportion of true negatives among actual negatives.

[Link]-ROC: Model's ability to distinguish classes.

7. AUC-PRC: Precision-recall trade-off assessment.

8. Log-Loss: Measures predicted probability accuracy.

Choose the metric that best aligns with your specific goals and priorities, as each metric
emphasizes different aspects of model performance.

2. What is the difference between a binary logistic regression and a multinomial


logisticregression? How do you choose which one to use for your data?

➢ Binary logistic regression is used when you have a binary (two-class) outcome variable,
and it predicts the probability of belonging to one of the two classes. It's suitable for
problems like yes/no or true/false.

Multinomial logistic regression, on the other hand, is used for multinomial classification
where the outcome variable has more than two unordered categories. It predicts the
probabilities of belonging to each of these categories. Use it when dealing with problems
that have multiple, non-ordered classes.

The choice between the two depends on the nature of your outcome variable and the
number of classes you need to predict.

Suggested Reference:

• [Link]
296caae933ec

• [Link]
• [Link]

36
References used by the students:
[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

37
Experiment No 6: K-NN classifier

Date:

Competency and Practical Skills:

Relevant CO: 3, 5

Objectives:

1. To understand how KNN works.

2. To split dataset in Train/Test.

3. To learn to train classifier

Implementation:

1. Implement a KNN classifier using the scikit-learn library.

2. Train the model using a binary classification dataset of your choice.

3. Evaluate the performance of the model using metrics such as accuracy, precision,
recall, and F1-score.

Source Code with Output:

Implementation 1:

Program:
# Import necessary libraries
from [Link] import load_iris
from sklearn.model_selection import train_test_split
from [Link] import KNeighborsClassifier
from [Link] import accuracy_score, confusion_matrix

# Load the Iris dataset (a common dataset for classification)


data = load_iris()
X = [Link]
y = [Link]

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)

# Create a KNN classifier with a specified number of neighbors (e.g., 3 neighbors)


knn = KNeighborsClassifier(n_neighbors=3)

# Train the KNN model on the training data


[Link](X_train, y_train)

# Make predictions on the test data


y_pred = [Link](X_test)

# Calculate accuracy and confusion matrix


accuracy = accuracy_score(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)

38
# Display the results
print("Accuracy:", accuracy)
print("Confusion Matrix:\n", conf_matrix)

Output:

Implementation 2:

Program:
# Import necessary libraries
from [Link] import load_breast_cancer
from sklearn.model_selection import train_test_split
from [Link] import KNeighborsClassifier
from [Link] import accuracy_score, confusion_matrix
import pandas as pd

# Load the Breast Cancer dataset


data = pd.read_csv('[Link]')
X = data[['dbt']]
y = data['data']

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)

# Create a KNN classifier with a specified number of neighbors (e.g., 5 neighbors)


knn = KNeighborsClassifier(n_neighbors=5)

# Train the KNN model on the training data


[Link](X_train, y_train)

# Make predictions on the test data


y_pred = [Link](X_test)

# Calculate accuracy and confusion matrix


accuracy = accuracy_score(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)

# Display the results


print("Accuracy:", accuracy)
print("Confusion Matrix:\n", conf_matrix)

39
Output:

Implementation 3:

Program:
from [Link] import accuracy_score, precision_score, recall_score, f1_score

from prac4imp2 import y_test, y_pred

# Calculate accuracy
accuracy = accuracy_score(y_test, y_pred)
print("Accuracy:", accuracy)

# Calculate precision
precision = precision_score(y_test, y_pred)
print("Precision:", precision)

# Calculate recall
recall = recall_score(y_test, y_pred)
print("Recall:", recall)

# Calculate F1-score
f1 = f1_score(y_test, y_pred)
print("F1-Score:", f1)

Output:

Conclusion:
In practice, the k-NN classifier is a valuable tool for tasks that rely on the concept of similarity and
where data points with similar features tend to have similar target values. Its simplicity, flexibility, and
ability to handle both classification and regression tasks make it a versatile choice for various machine
learning applications.
40
Related Questions:

1. What are some common performance metrics used to evaluate the accuracy of
a KNNclassifier, and how do you interpret them?
➢ Common performance metrics for evaluating a K-Nearest Neighbors (KNN) classifier:

1. Accuracy: Measures overall correctness of predictions.

2. Precision: Proportion of true positives among positive predictions.

3. Recall (Sensitivity): Proportion of true positives among actual positives.

4. F1-Score: Balances precision and recall.

5. Specificity: Proportion of true negatives among actual negatives.

6. ROC Curve and AUC-ROC: Trade-off between true positive rate and false positive rate.

7. AUC-PRC: Precision-recall trade-off assessment, useful for imbalanced data.

8. Kappa Statistic: Measures agreement between predictions and actual labels,


considering chance.

Choose the metric that aligns with your classification goals, considering factors like
class balance and the trade-off between false positives and false negatives.

2. How do you choose the value of K in KNN?

➢ To choose the value of K in K-Nearest Neighbors (KNN):

1. Start with an initial range of K values (e.g., 1, 3, 5, 7).

2. Use cross-validation to assess model performance for different K values.

3. Perform grid search to find the best K value along with other hyperparameters.

4. Consider domain knowledge and problem characteristics.

5. Use the "elbow method" to identify an optimal K based on performance curves.

6. Adjust K for class imbalance, giving more weight to the minority class if needed.

7. Continuously evaluate and fine-tune K for the desired trade-off between bias and variance.

8. Finally, assess the model's performance on a separate test dataset to ensure generalization.

The choice of K should be data-specific and based on rigorous experimentation and validation.

41
3. What are the pros and cons of using KNN for classification tasks?

➢ Pros of K-Nearest Neighbors (KNN) for Classification:

1. Simplicity: KNN is easy to understand and implement.

2. No Assumptions: It doesn't assume a specific data distribution, making it versatile.

3. Flexibility: Suitable for various classification tasks, including binary and multiclass problems.

4. Local Patterns: Robust to noisy data and outliers as it focuses on local patterns.

5. Interpretability: Decision-making process is interpretable based on nearest neighbors.

6. Adaptability: Can easily incorporate new data points without retraining.

Cons of KNN for Classification:

1. Computational Complexity: Can be slow with large datasets or high-dimensional feature


spaces.

2. Parameter Selection: Choosing the right K value can be challenging.

3. Sensitivity to Distance Metric: Performance depends on the choice of distance metric.

4. Class Imbalance: Biased toward the majority class in imbalanced datasets.

5. Curse of Dimensionality: Challenged in high-dimensional spaces.

6. Slow Predictions: May be slow for large datasets.

7. Data Preprocessing: Sensitive to data preprocessing steps like feature scaling.

KNN is best suited for smaller, low-dimensional datasets and is sensitive to parameter choices
and data quality.

Suggested Reference:

• [Link]

• [Link]

42
References used by the students:
[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

43
Experiment No 7: Clustering Model

Date:

Competency and Practical Skills:

Relevant CO: 3, 5

Objectives:

1. To understand how clustering model.

2. To learn about L-means clustering algorithm.

Implementation:

1. Implement k-means clustering using scikit-learn.

2. Apply k-means to a dataset of your choice.

3. Visualize the results using Matplotlib.

Source Code with Output:

Implementation 1:
Program:
# Import necessary libraries
import numpy as np
from [Link] import KMeans
import [Link] as plt

# Generate synthetic data


[Link](0)
X = [Link](100, 2) # 100 data points with 2 features

# Create a K-Means clustering model with a specified number of clusters (e.g., 3


clusters)
kmeans = KMeans(n_clusters=3)

# Fit the K-Means model to the data


[Link](X)

# Get the cluster labels for each data point


labels = kmeans.labels_

# Get the cluster centers


cluster_centers = kmeans.cluster_centers_

# Plot the data points and cluster centers


[Link](X[:, 0], X[:, 1], c=labels)
[Link](cluster_centers[:, 0], cluster_centers[:, 1], marker='x', s=200,
color='red')
[Link]("K-Means Clustering")
[Link]("Feature 1")
[Link]("Feature 2")
[Link]()

44
Output:

Implementation 2:
Program:
# Import necessary libraries
from [Link] import load_iris
from [Link] import KMeans
import [Link] as plt

# Load the Iris dataset


data = load_iris()
X = [Link] # We are using the features for clustering

# Create a K-Means clustering model with a specified number of clusters (e.g., 3


clusters)
kmeans = KMeans(n_clusters=3)

# Fit the K-Means model to the data


[Link](X)

# Get the cluster labels for each data point


labels = kmeans.labels_

# Get the cluster centers


cluster_centers = kmeans.cluster_centers_

# Plot the data points and cluster centers


[Link](X[:, 0], X[:, 1], c=labels)
[Link](cluster_centers[:, 0], cluster_centers[:, 1], marker='x', s=200,
color='red')
[Link]("K-Means Clustering of Iris Dataset")
[Link]("Feature 1")
[Link]("Feature 2")
[Link]()

45
Output:

Implementation 3:
Program:
# Import necessary libraries
from [Link] import load_iris
from [Link] import KMeans
import [Link] as plt

# Load the Iris dataset


data = load_iris()
X = [Link] # We are using the features for clustering

# Create a K-Means clustering model with a specified number of clusters (e.g., 3


clusters)
kmeans = KMeans(n_clusters=3)

# Fit the K-Means model to the data


[Link](X)

# Get the cluster labels for each data point


labels = kmeans.labels_

# Get the cluster centers


cluster_centers = kmeans.cluster_centers_

# Create a scatter plot to visualize the clusters


[Link](figsize=(8, 6))
[Link](X[:, 0], X[:, 1], c=labels, cmap='viridis', s=50)
[Link](cluster_centers[:, 0], cluster_centers[:, 1], marker='x', s=200,
color='red', label='Cluster Centers')
[Link]("K-Means Clustering of Iris Dataset")
[Link]("Feature 1")
[Link]("Feature 2")
[Link]()
[Link]()

46
Output:

Conclusion:

In conclusion, clustering models are unsupervised machine learning techniques designed to identify
natural groupings or patterns in data.
In practice, clustering models are invaluable for uncovering patterns and structures within data,
aiding in data exploration, segmentation, and decision-making. The choice of clustering algorithm
depends on the characteristics of the data and the specific problem at hand. Evaluating clustering
results and understanding the domain context are essential for successful applications of clustering
models.

Related Questions:

1. What is the difference between classification and clustering algorithm?


➢ Classification and Clustering are two different types of algorithms in machine learning:

- Classification is a supervised learning technique where the algorithm learns to assign


predefined class labels to data based on labeled training data. Its objective is to predict the
class of unseen data points.

- Clustering is an unsupervised learning technique where the algorithm groups data points into
clusters based on their inherent similarities without prior knowledge of class labels. Its
objective is to discover patterns or groupings within the data.

The key differences include the learning type (supervised vs. unsupervised), the output
(predicted labels vs. data grouping), and the use cases (classification for labeling, clustering for
pattern discovery).

47
2. What are the different clustering algorithms used in real-time applications?
Clustering algorithms used in real-time applications:

1. K-Means:Divides data into K clusters based on similarity.

2. Hierarchical Clustering: Builds a hierarchy of clusters by merging or splitting clusters.

3. DBSCAN: Groups data points based on density, suitable for varying shapes and sizes.

4. OPTICS: An extension of DBSCAN that provides hierarchical cluster representations.

5. Mean Shift: Shifts data points toward density peaks for non-uniform data.

6. Agglomerative Clustering: Merges similar clusters to create a hierarchy.

7. Spectral Clustering: Uses eigenvectors for non-convex clusters.

8. Affinity Propagation:Identifies exemplar points to represent clusters.

9. Fuzzy C-Means: Allows data points to belong to multiple clusters with varying degrees.

10. Stream Clustering Algorithms: Designed for continuous data streams.

The choice depends on data characteristics, the number of clusters, and computational
resources. Each algorithm has specific strengths and use cases.

Suggested Reference:

• [Link]

• [Link]

• [Link]

48
References used by the students:

[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

49
Experiment No 8: Neural Network

Date:

Competency and Practical Skills:

Relevant CO: 3, 5

Objectives:

1. To understand the basic difference between biological neural network and artificial
neural network

2. To lean the mathematical structure of artificial neural network

3. To implement neural network

Implementation:

1. Implement a simple neural network using TensorFlow or Keras on a dataset of your


choice.

2. Train the model and evaluate its performance using metrics such as accuracy and
loss.

Source Code with Output:

Implementation 1:

Program:
# Import necessary libraries
import numpy as np
from [Link] import load_iris
from sklearn.model_selection import train_test_split
from [Link] import Sequential
from [Link] import Dense
from [Link] import to_categorical
from [Link] import Adam

# Load the Iris dataset


data = load_iris()
X = [Link]
y = [Link]

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)

# One-hot encode the target labels


y_train = to_categorical(y_train)
y_test = to_categorical(y_test)

# Create a simple neural network model


model = Sequential()
[Link](Dense(8, input_dim=4, activation='relu'))
[Link](Dense(3, activation='softmax'))

# Compile the model


50
[Link](loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.001),
metrics=['accuracy'])

# Train the model


[Link](X_train, y_train, epochs=100, batch_size=5, verbose=1)

# Evaluate the model on the test data


loss, accuracy = [Link](X_test, y_test)
print(f"Test Loss: {loss:.4f}")
print(f"Test Accuracy: {accuracy:.4f}")

Output:

Implementation 2:

Program:
# Import necessary libraries
import numpy as np
from [Link] import load_iris
from sklearn.model_selection import train_test_split
from [Link] import Sequential
from [Link] import Dense
from [Link] import to_categorical
from [Link] import Adam

# Load the Iris dataset


data = load_iris()
X = [Link]
y = [Link]

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2,
random_state=42)

# One-hot encode the target labels


y_train = to_categorical(y_train)
y_test = to_categorical(y_test)

# Create a simple neural network model


model = Sequential()
[Link](Dense(8, input_dim=4, activation='relu'))
[Link](Dense(3, activation='softmax'))

# Compile the model


[Link](loss='categorical_crossentropy', optimizer=Adam(learning_rate=0.001),
metrics=['accuracy'])

# Train the model


51
[Link](X_train, y_train, epochs=100, batch_size=5, verbose=1)

# Evaluate the model on the test data


loss, accuracy = [Link](X_test, y_test)
print(f"Test Loss: {loss:.4f}")
print(f"Test Accuracy: {accuracy:.4f}")

Output:

Conclusion:
Neural networks have significantly advanced the state of the art in machine learning and have
demonstrated their effectiveness in a wide range of tasks. They continue to be an area of active research
and innovation, pushing the boundaries of what's possible in artificial intelligence and deep learning.

Related Questions:

1. What are the different types of neural networks and their applications?
➢ Different types of neural networks and their applications:

1. Feedforward Neural Network (FNN): Traditional regression and classification tasks.

2. Convolutional Neural Network (CNN): Image recognition, object detection, facial recognition.

3. Recurrent Neural Network (RNN): Time series prediction, NLP, speech recognition.

4. Long Short-Term Memory (LSTM): Time series forecasting, machine translation.

5. Gated Recurrent Unit (GRU): Similar to LSTM, used for NLP and sequences.

6. Radial Basis Function Network (RBFN): Function approximation, pattern recognition.

7. Autoencoder: Data compression, feature learning, anomaly detection.

8. Variational Autoencoder (VAE): Data generation, data imputation.

9. Generative Adversarial Network (GAN): Image generation, style transfer.

10. Self-Organizing Map (SOM): Dimensionality reduction, clustering.

52
11. Hopfield Network: Associative memory, optimization problems.

12. Kohonen SOM: Clustering, visualization, feature extraction.

13. Echo State Network (ESN): Time series prediction, speech recognition.

14. Transformer: NLP, machine translation.

15. BERT: Advanced NLP tasks.

16. Siamese Network: Face and signature verification, one-shot learning.

17. Neural Turing Machine (NTM): Memory-augmented networks, algorithm learning.

18. Reservoir Computing: Time series prediction, speech recognition.

19. Capsule Network (CapsNet): Image analysis, object recognition.

Each type is suited for specific applications, addressing a wide range of tasks in computer vision,
NLP, time series analysis, and more. The choice depends on the problem at hand.

2. What is regularization in neural networks and why is it important?


➢ Regularization in neural networks is a critical technique to prevent overfitting, where a model
fits the training data too closely, causing poor generalization. It's important because it:

1. Prevents Overfitting: Neural networks can be overly complex, memorizing training data noise.
Regularization constraints model complexity to avoid overfitting.

2. Improves Generalization: It helps models perform well on both training and new, unseen data,
which is essential for practical applications.

3. Increases Robustness: Regularization encourages models to focus on essential features and


patterns, making them more robust and less sensitive to noise.

4. Reduces Model Complexity: It adds penalties to the loss function, promoting simpler,
interpretable models.

Common regularization techniques include L1 and L2 regularization, dropout, early stopping, data
augmentation, weight decay, and batch normalization. These methods ensure neural networks
generalize effectively and produce reliable results.

3. What are some common activation functions used in neural networks?


➢ Common activation functions in neural networks:

1. Sigmoid: Outputs values between 0 and 1, used for binary classification and probability
estimation.

2. Tanh (Hyperbolic Tangent): Outputs values between -1 and 1, useful in hidden layers.

53
3. ReLU (Rectified Linear Unit): Outputs the input for positive values, widely used in hidden layers
due to computational efficiency.

4. Leaky ReLU: A variant of ReLU that allows a small gradient for negative values to prevent "dying
ReLU" problem.

5. PReLU (Parametric ReLU): Leaky ReLU with a learnable slope for negative values.

6. ELU (Exponential Linear Unit): Smooth and addresses the vanishing gradient problem in deep
networks.

7. SELU (Scaled Exponential Linear Unit): Self-normalizing and suitable for deep networks.

8. Swish: A smooth activation function competitive with ReLU.

9. GRU (Gated Recurrent Unit): Used in recurrent neural networks (RNNs) and LSTM-like
structures.

10. Hard Tanh: A clipped version of tanh to limit extreme values.

Selecting the right activation function depends on the specific task, network architecture, and
empirical performance. Experimentation is often necessary to determine the most suitable choice.

4. What are some real-world applications of neural networks?

➢ Real-world applications of neural networks:

1. Computer Vision: Object detection, facial recognition, and medical image analysis.

2. Natural Language Processing (NLP): Machine translation, chatbots, and sentiment analysis.

3. Speech and Audio Processing: Speech recognition, speaker identification, and noise reduction.

4. Healthcare: Disease diagnosis, medical imaging, and drug discovery.

5. Finance: Stock market prediction, fraud detection, and credit scoring.

6. Recommendation Systems: Content and product recommendations.

7. Autonomous Vehicles: Self-driving cars and drones.

8. Anomaly Detection: Network traffic analysis, fraud detection, and quality control.

9. Game Playing: Chess, Go, and video game playing.

10. Agriculture: Crop disease detection and yield prediction.

11. Environmental Monitoring: Climate modeling and pollution monitoring.

12. Energy Management: Predictive maintenance and energy optimization.

54
13. Robotics: Robot control and human-robot interaction.

14. Social Media: Trend analysis, sentiment monitoring, and content filtering.

15. Marketing: Customer analytics, campaign optimization, and churn prediction.

16. Language Generation: Content generation and chatbot responses.

17. Neuroscience: Brain-computer interfaces and neural signal decoding.

18. Security: Intrusion detection and cybersecurity.

Neural networks play a crucial role in solving complex problems across diverse fields, contributing
to advancements in technology and research.

55
Suggested Reference:

• [Link]

• [Link]

References used by the students:


[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

56
Experiment No 9: Deep Neural Network

Date:

Competency and Practical Skills:

Relevant CO: 4, 5

Objectives:

1. To understand the basic difference between neural network and Deep neural
network

2. To understand various activation functions.

3. To implement deep neural network on real-time dataset.

Implementation:

1. Design a deep neural network architecture using a framework such as TensorFlow or


Keras.

2. Choose the number of layers, number of neurons per layer, activation functions, and
regularization techniques.

3. Train the deep neural network on the given dataset.

4. Evaluate its performance using metrics such as accuracy and loss.

Source Code with Output:

Implementation 1:
Program:
# Import necessary libraries
import tensorflow as tf
from tensorflow import keras
from [Link] import layers

# Define the deep neural network model


model = [Link]([
# Convolutional layers
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),

# Flatten layer
[Link](),

# Fully connected layers


[Link](64, activation='relu'),
[Link](10, activation='softmax') # Output layer for 10 classes (e.g., digits
0-9)
])

57
# Compile the model
[Link](optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Display model summary


[Link]()
Output:

Implementation 2:
Program:
# Import necessary libraries
import tensorflow as tf
from tensorflow import keras
from [Link] import layers

# Define the deep neural network model


model = [Link]([
# Input layer
[Link](shape=(28, 28, 1)),

# Convolutional layers
layers.Conv2D(32, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),

# Fully connected layers


[Link](),
[Link](128, activation='relu'),

# Output layer
[Link](10, activation='softmax')
])

# Compile the model


[Link](optimizer='adam', loss='categorical_crossentropy',
metrics=['accuracy'])

# Display model summary


[Link]()

58
Output:

Implementation 3:
Program:
# Import necessary libraries
import tensorflow as tf
from tensorflow import keras
from [Link] import layers
from [Link] import mnist

# Load and preprocess the MNIST dataset


(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0 # Normalize pixel values to the range
[0, 1]

# Build the deep neural network model


model = [Link]([
# Flatten layer to convert 28x28 images to a flat vector
[Link](input_shape=(28, 28)),

# Fully connected layers


[Link](128, activation='relu'),
[Link](0.2), # Dropout for regularization
[Link](64, activation='relu'),

# Output layer
[Link](10, activation='softmax')
])

# Compile the model


[Link](optimizer='adam', loss='sparse_categorical_crossentropy',
metrics=['accuracy'])

# Train the model


[Link](x_train, y_train, epochs=5, batch_size=32, validation_data=(x_test, y_test))

# Evaluate the model on the test data


test_loss, test_accuracy = [Link](x_test, y_test)
print(f"Test Loss: {test_loss:.4f}")
print(f"Test Accuracy: {test_accuracy:.4f}")
59
Output:

Implementation 4:
Program:
# Evaluate the model on the test data
test_loss, test_accuracy = [Link](x_test, y_test)
print(f"Test Loss: {test_loss:.4f}")
print(f"Test Accuracy: {test_accuracy:.4f}")

Output:

Conclusion:
Deep neural networks have brought about significant advances in the field of artificial intelligence
and have achieved state-of-the-art performance in various tasks. They continue to push the boundaries
of what can be achieved in machine learning and are at the forefront of technology breakthroughs and
applications across diverse industries.

Related Questions:

1. What are the different types architectures of Deep Neural Network?


➢ Different types of Deep Neural Network (DNN) architectures:

1. Feedforward Neural Network (FNN):


- Basic DNN with input, hidden, and output layers.
- Used for regression and classification tasks.

2. Multilayer Perceptron (MLP):


- DNN with multiple hidden layers for complex, non-linear tasks.

3. Convolutional Neural Network (CNN):


- Specialized for image and grid-like data, using convolutional layers.
- Common in image recognition and computer vision.

4. Recurrent Neural Network (RNN):


- Processes sequential data with feedback loops.
- Used in natural language processing and time series analysis.

5. Long Short-Term Memory (LSTM):


- RNN variant with memory cells for long-range dependencies.
60
- Ideal for machine translation and speech recognition.

6. Gated Recurrent Unit (GRU):


- Simplified RNN variant for memory in sequential data.

7. Autoencoder:
- Learns efficient data representations with encoder and decoder.
- Used for dimensionality reduction and anomaly detection.

8. Variational Autoencoder (VAE):


- Extends autoencoders with probabilistic features.
- Used for data generation, imputation, and generative modeling.

9. Generative Adversarial Network (GAN):


- Comprises a generator and discriminator trained in competition.
- Used for data generation, style transfer, and data augmentation.

10. Siamese Network:


- Uses two identical subnetworks to compare and verify similarity.

11. Transformer:
- Designed for NLP tasks with self-attention mechanisms.
- Efficient for sequence-to-sequence tasks.

12. Capsule Network (CapsNet):


- Focuses on hierarchical data relationships for pattern recognition.

13. Radial Basis Function Network (RBFN):


- Uses radial basis functions for non-linear approximation.

14. Hopfield Network:


- Associative memory network with recurrent connections.

Each DNN architecture is suited for specific tasks and data types, showcasing the versatility of
neural networks in solving a wide range of problems. The choice depends on the problem's nature
and requirements.

2. What is learning rate and batch size?

➢ Learning Rate:
- The learning rate is a hyperparameter that determines the step size at which a neural network's
weights are updated during training.
- It controls how quickly or slowly a neural network converges to a solution. A high learning rate
makes the training process faster but can lead to overshooting the optimal solution. A low learning
rate ensures stability but may require more training epochs.
- It's a crucial parameter to tune to balance training speed and model accuracy. Common learning
rates range from 0.1 to 0.0001.

➢ Batch Size:
- The batch size is a hyperparameter that defines the number of training examples used in each
forward and backward pass during one iteration of model training.
61
- Large batch sizes can speed up training by taking advantage of parallel processing but may
require more memory. Small batch sizes may lead to slower training but can provide a more
accurate estimate of the gradient.
- The choice of batch size depends on available hardware and the dataset. Common batch sizes
range from 32 to 256.

Both learning rate and batch size play critical roles in training neural networks effectively. The
optimal values often depend on the specific problem and the network architecture being used.
They are essential hyperparameters that machine learning practitioners must tune to achieve the
best model performance.

62
Suggested Reference:

• [Link]

• [Link]

References used by the students:


[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

63
Experiment No 10: Convolutional Neural Network

Date:

Competency and Practical Skills:

Relevant CO: 4, 5

Objectives:

1. To understand the basic difference between neural network and Deep neural
network

2. To understand various activation functions.

3. To implement deep neural network on real-time dataset.

Implementation:

1. Design a convolutional neural network architecture using a framework such as


TensorFlow or Keras.

2. Choose the number of convolutional layers, pooling layers, fully connected layers,
and activation functions.

3. Train the deep neural network on the given dataset. ( i.e. example cat vs dog, MNIST
etc).

4. Evaluate the trained model's performance using metrics such as accuracy, precision,
recall, and F1-score.

Source Code with Output:

Implementation 1:

Program:
# Import necessary libraries
import tensorflow as tf
from tensorflow import keras
from [Link] import layers

num_classes = 10 # Define the number of classes in your problem

# Define the CNN model


model = [Link]([
# Convolutional layers
layers.Conv2D(32, (5, 5), activation='relu', input_shape=(32, 32, 3)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (5, 5), activation='relu'),
layers.MaxPooling2D((2, 2)),

# Flatten layer
[Link](),

64
# Fully connected layers
[Link](120, activation='relu'),
[Link](84, activation='relu'),

# Output layer
[Link](num_classes, activation='softmax') # Adjust 'num_classes' for your
specific problem
])

# Compile the model


[Link](optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Display model summary


[Link]()

Output:

Implementation 2:

Program:
# Import necessary libraries
import tensorflow as tf
from tensorflow import keras
from [Link] import layers

# Define the number of classes


num_classes = 10 # Adjust this for your specific problem

# Define the CNN model


model = [Link]([
# Convolutional layers
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(64, 64, 3)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(128, (3, 3), activation='relu'),
layers.MaxPooling2D((2, 2)),

# Flatten layer
[Link](),

# Fully connected layers


[Link](256, activation='relu'),
[Link](0.5), # Dropout for regularization

65
[Link](128, activation='relu'),

# Output layer
[Link](num_classes, activation='softmax') # Adjust 'num_classes' for your
specific problem
])

# Compile the model


[Link](optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Display model summary


[Link]()

Output:

Implementation 3:

Program:
# Import necessary libraries
import tensorflow as tf
from tensorflow import keras
from [Link] import layers
from [Link] import cifar10

# Load the CIFAR-10 dataset


(x_train, y_train), (x_test, y_test) = cifar10.load_data()

# Normalize pixel values to the range [0, 1]


x_train, x_test = x_train / 255.0, x_test / 255.0

# Define the number of classes


num_classes = 10

# Convert class vectors to one-hot encoding


y_train = [Link].to_categorical(y_train, num_classes)
y_test = [Link].to_categorical(y_test, num_classes)

# Define the CNN model


model = [Link]([
# Convolutional layers
layers.Conv2D(32, (3, 3), activation='relu', input_shape=(32, 32, 3)),
layers.MaxPooling2D((2, 2)),
layers.Conv2D(64, (3, 3), activation='relu'),

66
layers.MaxPooling2D((2, 2)),
layers.Conv2D(128, (3, 3), activation='relu'),

# Flatten layer
[Link](),

# Fully connected layers


[Link](256, activation='relu'),
[Link](0.5), # Dropout for regularization
[Link](128, activation='relu'),

# Output layer
[Link](num_classes, activation='softmax')
])

# Compile the model


[Link](optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])

# Train the model


[Link](x_train, y_train, epochs=10, batch_size=64, validation_data=(x_test, y_test))

Output:

Implementation 4:

Program:
from [Link] import accuracy_score, precision_score, recall_score, f1_score

# Assuming you have already trained the model, make predictions on the test data
y_pred = [Link](x_test)

# Convert one-hot encoded predictions and ground truth to class labels


y_pred_classes = y_pred.argmax(axis=-1)
y_true_classes = y_test.argmax(axis=-1)

# Calculate metrics
accuracy = accuracy_score(y_true_classes, y_pred_classes)
precision = precision_score(y_true_classes, y_pred_classes, average='weighted')
recall = recall_score(y_true_classes, y_pred_classes, average='weighted')
f1 = f1_score(y_true_classes, y_pred_classes, average='weighted')

print(f"Accuracy: {accuracy:.4f}")
print(f"Precision: {precision:.4f}")
print(f"Recall: {recall:.4f}")
print(f"F1-Score: {f1:.4f}")

Output:

67
Conclusion:
CNNs have revolutionized the field of computer vision and have set new benchmarks for visual data
analysis tasks. They continue to drive advancements in technology and play a critical role in applications
that rely on the interpretation and understanding of visual content.

Related Questions:

1. What is the convolutional layer?


➢ A convolutional layer is a fundamental component in convolutional neural networks (CNNs),
especially for image-related tasks. It performs feature extraction by applying small filters to
the input data. Here's a brief explanation:

1. Feature Extraction: Convolutional layers apply learnable filters to the input data, enabling the
network to detect features like edges, textures, and patterns.

2. Local Receptive Fields: Each filter has a small region (local receptive field) that it operates on,
and its weights are shared across the entire input. This reduces the number of parameters.

3. Convolution Operation: The filter slides or convolves across the input data, computing dot
products within its local receptive field. This process creates feature maps that highlight specific
patterns.

4. Stride and Padding: Stride determines how much the filter shifts during each slide, and padding
controls the size of the feature map.

5. Non-Linearity: Typically, a non-linear activation function (e.g., ReLU) is applied to introduce


non-linearity.

6. Pooling: Optional pooling layers may follow to reduce feature map dimensions, making the
network more efficient and less prone to overfitting.

Convolutional layers are essential for capturing hierarchical and spatial features in data, making
CNNs ideal for image recognition, object detection, and more. Stacking multiple convolutional
layers allows the network to learn increasingly complex features.

2. What is learning rate and batch size used in CNN?

➢ Learning Rate and Batch Size are two important hyperparameters used in training
convolutional neural networks (CNNs) and other deep learning models.

Learning Rate:
- The learning rate is a hyperparameter that determines the size of steps taken during the
optimization process (e.g., gradient descent) to update the model's weights.
68
- In CNNs, it controls how much the model's parameters are adjusted based on the gradient of the
loss function with respect to those parameters.
- A high learning rate can make training faster but may lead to overshooting the optimal solution,
while a low learning rate can improve convergence but may require longer training times.
- Common learning rates for CNNs typically range from 0.1 to 0.0001, but the optimal value can
vary based on the problem and model architecture.

Batch Size:
- The batch size is a hyperparameter that specifies the number of data samples (e.g., images) used
in each forward and backward pass during a single training iteration.
- In CNN training, data is divided into batches, and gradients are computed for each batch. The
model's weights are updated after processing each batch.
- The choice of batch size affects training speed, memory usage, and the quality of the weight
updates. Smaller batch sizes provide a more accurate estimate of the gradient but can slow down
training due to frequent weight updates. Larger batch sizes can speed up training through parallel
processing but may result in a noisier gradient estimate.
- Typical batch sizes for CNNs range from 32 to 256, but the optimal batch size depends on factors
like available hardware and the dataset size.

Both learning rate and batch size are critical for effective CNN training. Properly tuning these
hyperparameters is often necessary to achieve the best model performance, and the optimal
values can vary from one problem to another.

69
Suggested Reference:

• [Link]

• [Link]
network

References used by the students:


[Link]
[Link]

Rubric wise marks obtained:

Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score

Implementation Implementation is Implementation is Implementation is Implementation is


not presented. complete. It does not complete. It does not complete. It meets all
compile and run. meet all the the specifications and
specifications and does works for all test data.
not work for all test
data.

Results Results are not Partially corrected The results are correct, The results are
included. results. but not in the proper correct. Well
format. structured,

Conclusion No conclusion is In-Correct conclusion Partially correct Conclusion meets the


present. is presented. conclusion. requirements of the
experiment.

References No references are Incorrect references Related references are Related references are
included by the are included. included but are not included and well
students. well structured. structured.

Question Not able answer a Answers are partially Answers are correct. Answers are correct.
Answers single question. correct. No in-depth Having in-depth
understating. knowledge of concept.

Total

70

Common questions

Powered by AI

The bias term (intercept) in a linear regression model allows the regression line to fit the data more accurately by shifting it vertically along the Y-axis. Without it, the line would be forced to pass through the origin, which could significantly reduce the model’s ability to capture the true relationship between the variables, particularly if the data is not centered around zero .

Mean Squared Error (MSE) measures the average squared difference between predicted and actual values, reflecting the model’s accuracy. R-squared indicates the proportion of variance explained by the model, showing the goodness of fit. Together, they provide insight into both the model’s predictive accuracy and its overall quality .

The implementation for CIFAR-10, which involves more complex and colorful images, typically requires deeper networks with more convolutional and pooling layers to accurately capture detailed features. In contrast, MNIST's simpler grayscale images demand less complexity, often allowing effective results with shallower networks .

Convolutional layers contain filters that perform the convolution operation by sliding over input data. Key components include learnable parameters (filter weights) and a local receptive field that allows for spatial hierarchies of features. This facilitates detection of patterns such as edges and textures, essential for recognizing complex visual structures in data .

Logistic regression is used for binary classification, where the outcome variable has two possible categories (true/false). Multinomial logistic regression is used when the outcome variable has more than two unordered categories, such as predicting types of flowers. The choice depends on the number and nature of categories in the outcome variable .

Batch size affects the stability and speed of the training process, with smaller batches providing noisier but potentially more informative updates, while larger batches offer smoother but less frequent updates. The learning rate influences how quickly weights are adjusted during training. Both need fine-tuning to balance training speed and convergence to an optimal model .

Hyperparameter tuning is crucial as it directly impacts model performance metrics such as accuracy and loss. Proper tuning can significantly enhance model accuracy by optimizing convergence and generalization, while poor tuning can lead to overfitting or underfitting, negatively affecting both accuracy and computational efficiency .

Using a large number of neighbors in a K-NN classifier can lead to over-smoothing, where the model becomes less sensitive to variations in the data and may oversimplify the classification boundary. This can reduce accuracy, especially if the classes are not well-separated, and can increase computational costs .

Dropout layers randomly deactivate a portion of neurons during training, preventing complex co-adaptations, thus helping mitigate overfitting. By forcing the network to rely on distributed representations, dropout enhances model robustness and generalization to unseen data .

Conditional probability is used in scenarios where the occurrence of one event influences the likelihood of another event. Mathematically, it is formulated as P(A|B) = N(A∩B)/N(B), where P(A|B) is the probability of event A occurring given that event B has occurred. This relationship is crucial in fields like finance and machine learning for making informed predictions and decisions .

You might also like