Aml Lab Manual
Aml Lab Manual
Certificate
Place:
Date:
1. To understand basic statistical properties of data like mean, median and mode
Implementation:
1. Write a program to compute mean, median and mode for given data using preferred programming
language.
Code:-
import matplotlib.pyplot as plt
n = len(data)
mean_value = sum(data) / n
sorted_data = sorted(data) if
n % 2 == 0:
median_value = (sorted_data[n//2 - 1] + sorted_data[n//2]) / 2
else:
median_value = sorted_data[n//2]
frequency = {}
for num in data:
frequency[num] = frequency.get(num, 0) + 1
max_freq = max(frequency.values())
mode_value = [k for k, v in frequency.items() if v == max_freq][0]
plt.legend()
plt.title("Histogram with Mean, Median, Mode")
plt.xlabel("Data values") plt.ylabel("Frequency")
plt.show()
Output:
Data: [10, 15, 8, 10, 20, 15, 10, 25, 30]
Mean: 15.88888888888889
Median: 15
Mode: 10
2. Plot the histogram for the data and show mean, median and mode in the histogram.
Related Questions:
Mean: The average of all values in a dataset, calculated by dividing the sum of values by the
number of values.
2
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Median: The middle value when the data is arranged in ascending or descending order.
2. Which measure of central tendency is preferred when the data set has extreme values?
When the dataset contains extreme values (outliers), the Median is preferred because it is not
influenced by unusually high or low values.
Mean can get “pulled” in the direction of outliers, giving a misleading picture of the data’s
center.
Suggested Reference:
● https://www.techtarget.com/searchdatacenter/definition/statistical-mean-median-mode-and-range
● https://www.statisticshowto.com/probability-and-statistics/statistics-definitions/mean-median-mode/
● https://www.twinkl.co.in/teaching-wiki/mean-median-mode-and-range
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
3
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Implementation:
# Normal Distribution
normal_data = np.random.normal(loc=0, scale=1, size=1000)
plt.hist(normal_data, bins=30, density=True, alpha=0.6, color='skyblue',
edgecolor="black")
x = np.linspace(-4, 4, 1000)
plt.plot(x, norm.pdf(x, 0, 1), 'r', linewidth=2, label="Normal PDF") plt.title("Normal
Distribution")
plt.legend()
plt.show()
# Poisson Distribution
poisson_data = np.random.poisson(lam=5, size=1000) plt.hist(poisson_data,
bins=15, density=True, alpha=0.6, color='lightgreen', edgecolor="black")
x = np.arange(0, max(poisson_data))
plt.plot(x, poisson.pmf(x, 5), 'r', linewidth=2, label="Poisson PMF") plt.title("Poisson
Distribution (λ=5)")
plt.legend()
plt.show()
# Bernoulli Distribution
bernoulli_data = bernoulli.rvs(p=0.5, size=1000)
plt.hist(bernoulli_data, bins=2, density=True, alpha=0.6, color='orange',
4
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
edgecolor="black")
plt.xticks([0,1])
plt.title("Bernoulli Distribution (p=0.5)")
plt.show()
2. Generate random samples from the distributions and visualize the results using Matplotlib.
5
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Related Questions:
2. What is the difference between normal distribution, Poisson distribution, and Bernoulli distribution?
Distribution Type Definition Example Shape
Symmetrical, bell-shaped distribution
Normal Human height, exam
Continuous defined by mean (μ) and standard Bell curve
Distribution scores
deviation (σ).
Probability of a given number of events Skewed,
Poisson Number of calls at a
Discrete occurring in a fixed interval of time or depends on
Distribution call center in 1 hour
space, with rate λ. λ
Coin toss
Bernoulli Probability of a binary outcome Two bars at
Discrete (Head/Tail), yes/no
Distribution (success/failure) with probability p. 0 and 1
events
6
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://www.healthknowledge.org.uk/public-health-textbook/research-methods/1b-statistical-methods/
statistical-distributions
● https://www.researchoptimus.com/article/normal-binomial-poisson-distribution.php
● http://www.eagri.org/eagri50/STAM101/pdf/lec07.pdf
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
7
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Implementation:
1. For a medical testing company, 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).
Prevalence(PriorProbability):
1
𝑃(𝐷) = = 0.001(probability of having the disease)
1000
𝑃(¬𝐷) = 0.999(probability of not having the disease)
Test Accuracy:
o False Positive Rate = 1% → 𝑃(Test Positive ∣ ¬𝐷) = 0.01
o True Negative Rate = 99% → 𝑃(Test Negative ∣ ¬𝐷) = 0.99
o False Negative Rate = 5% → 𝑃(Test Negative ∣ 𝐷) = 0.05
o True Positive Rate = 95% → 𝑃(Test Positive ∣ 𝐷) = 0.95
(b) Probability that a person actually has the disease given they test positive
(Bayes’ theorem)
𝑃(Positive ∣ 𝐷)𝑃(𝐷)
𝑃(𝐷 ∣ Positive) =
𝑃(Positive)
0.95 × 0.001
=
0.01094
0.00095
= ≈ 0.0868 (≈ 8.7%)
0.01094
2. 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?
Step 1: Probability of testing positive (law of total probability)
𝑃(Positive) = 𝑃(Positive ∣ 𝐷)𝑃(𝐷) + 𝑃(Positive ∣ ¬𝐷)𝑃(¬𝐷)
𝑃(Positive) = (0.95)(0.001) + (0.01)(0.999)
𝑃(Positive) = 0.00095 + 0.00999 = 0.01094
8
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
⬛Step 3: Interpretation
Even though the test is highly accurate, because the disease is very rare, the probability that a
patient actually has the disease given a positive test is only about:
8.7%
This is a classic example of how rare diseases and false positives can lead to counterintuitive
results in medical testing.
Related Questions:
Where:
𝑃(𝐴 ∣ 𝐵)= Probability of event A occurring given event B has occurred (posterior probability)
𝑃(𝐵 ∣ 𝐴)= Probability of event B occurring given event A has occurred (likelihood)
𝑃(𝐴)= Probability of event A occurring (prior probability)
𝑃(𝐵)= Probability of event B occurring (marginal probability)
Example:
If a test for a disease is positive, Bayes’ theorem helps calculate how likely it is that the person
actually has the disease, taking into account the test accuracy and disease prevalence.
Where:
𝑃(𝐴 ∣ 𝐵)= Probability of event A occurring given event B has occurred (posterior probability)
𝑃(𝐵 ∣ 𝐴)= Probability of event B occurring given event A has occurred (likelihood)
𝑃(𝐴)= Probability of event A occurring (prior probability)
9
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://www.mathsisfun.com/data/bayes-theorem.html
● https://plato.stanford.edu/entries/bayes-theorem/
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
10
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Objectives:
Implementation:
3. Evaluate the performance of the model using the mean squared error and R-squared metrics.
Code:-
OUTPUT:-
Model Coefficient (slope): 3.02
Model Intercept: 3.89
Mean Squared Error (MSE): 0.87
R-squared (R²): 0.98
12
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Related Questions:
Where:
𝑦i= actual value
𝑦^ i = predicted value
𝑛= number of data points
Interpretation:
Smaller MSE → better model performance (predictions are closer to actual values).
Squaring emphasizes larger errors.
b) R-squared (R²):
R² measures the proportion of variance in the dependent variable that is explained by the
independent variable(s).
Formula:
∑(𝑦i − 𝑦^ i ) 2
𝑅2 = 1 −
∑(𝑦i − 𝑦¯ )2
Where:
𝑦¯ = mean of actual values
Interpretation:
R² = 1 → perfect fit
R² = 0 → model explains none of the variance
R² < 0 → model is worse than using the mean as prediction
Definition:
Multivariate regression is a type of regression where more than one independent variable is used
to predict a dependent variable.
It’s an extension of simple linear regression (which uses only one independent variable).
General formula:
𝑦 = 𝑏0 + 𝑏1𝑥1 + 𝑏2𝑥2 + ⋯ + 𝑏n𝑥n + 𝜖
Where:
𝑦= dependent variable
𝑥1, 𝑥2, . . . , 𝑥n= independent variables
𝑏0= intercept, 𝑏1, 𝑏2, . . . , 𝑏n= coefficients
𝜖= error term
Example:
13
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://medium.datadriveninvestor.com/regression-in-machine-learning-296caae933ec
● https://www.analyticsvidhya.com/blog/2021/06/linear-regression-in-machine-learning/
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
14
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Implementation:
3. Evaluate the performance of the model using metrics such as accuracy, precision, recall, and
F1-score.
# Make predictions
y_pred = model.predict(X_test)
# Calculate metrics
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)
15
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
print("Accuracy:", accuracy)
print("Precision:", precision)
print("Recall:", recall)
print("F1-score:", f1)
Accuracy: 0.9649
Precision: 0.96
Recall: 0.98
F1-score: 0.97
Related Questions:
1. What are some common performance metrics used to evaluate the accuracy of a logistic regression
model, and how do you interpret them?
When evaluating a logistic regression model, especially for classification problems, the following
metrics are commonly used:
Recall Proportion of actual positives that are High recall → few false negatives; useful when
TP
(Sensitivity) correctly predicted. Formula: Recall =TP+FN missing a positive is costly (e.g., disease detection).
Balances precision and recall; useful when classes are
F1-score Harmonic mean of precision and recall.
imbalanced.
16
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
2. What is the difference between a binary logistic regression and a multinomial logistic regression?
How do you choose which one to use for your data?
How to choose:
If your target variable has two categories, use binary logistic regression.
If your target variable has more than two categories, use multinomial logistic regression (or
“softmax regression”).
17
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://medium.datadriveninvestor.com/regression-in-machine-learning-296caae933ec
● https://www.kdnuggets.com/2022/07/logistic-regression-work.html
● https://machinelearningmastery.com/logistic-regression-for-machine-learning/
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
18
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Implementation:
# Load dataset
data = load_breast_cancer()
X = data.data # Features
y = data.target # Labels (0 or 1)
3. Evaluate the performance of the model using metrics such as accuracy, precision, recall, and
F1-score.
# Make predictions
y_pred = knn_model.predict(X_test)
19
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
print("Accuracy:", accuracy)
print("Precision:", precision)
print("Recall:", recall)
print("F1-score:", f1)
OUTPUT:-
Accuracy: 0.9561
Precision: 0.9706
Recall: 0.9706
F1-score: 0.9706
Related Questions:
1. What are some common performance metrics used to evaluate the accuracy of a KNN classifier,
and how do you interpret them?
20
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Typical approach:
2. Choose K that gives highest validation accuracy or best balance between bias and variance.
3. What are the pros and cons of using KNN for classification tasks?
Pros:
Simple and intuitive, easy to implement.
Non-parametric → no assumption about data distribution.
Can handle multi-class classification naturally.
Flexible with different distance metrics (Euclidean, Manhattan, etc.).
Cons:
Computationally expensive for large datasets → must compute distance for all points at prediction
time.
Sensitive to irrelevant features and feature scaling → normalization is important.
Performance decreases with high-dimensional data (curse of dimensionality).
Sensitive to noisy data and outliers.
Suggested Reference:
● https://www.ibm.com/topics/knn
● https://www.scaler.com/topics/machine-learning/knn-algorithm-in-machine-learning/
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
21
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Implementation:
plt.title('K-Means Clustering')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
plt.legend()
plt.show()
22
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Related Questions:
24
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://www.geeksforgeeks.org/clustering-in-machine-learning/
● https://developers.google.com/machine-learning/clustering/overview
● https://serokell.io/blog/k-means-clustering-in-machine-learning
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
25
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
1. To understand the basic difference between biological neural network and artificial neural network
Implementation:
# Load dataset
data = load_iris()
X = data.data # Features
y = data.target.reshape(-1, 1) # Labels
# Standardize features
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
2. Train the model and evaluate its performance using metrics such as accuracy and loss.
26
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
OUTPUT:-
Epoch 1/50
12/12 [==============================] - 1s 15ms/step - loss: 1.0591 -
accuracy: 0.4048 - val_loss: 1.0312 - val_accuracy: 0.4167
Epoch 2/50
12/12 [==============================] - 0s 3ms/step - loss: 0.9782 -
accuracy: 0.5833 - val_loss: 0.9673 - val_accuracy: 0.5417
Epoch 3/50
12/12 [==============================] - 0s 3ms/step - loss: 0.9221 -
accuracy: 0.6786 - val_loss: 0.9120 - val_accuracy: 0.6250
...
Epoch 50/50
12/12 [==============================] - 0s 3ms/step - loss: 0.0198 -
accuracy: 0.9881 - val_loss: 0.0753 - val_accuracy: 0.9583
Related Questions:
1. What are the different types of neural networks and their applications?
Type Description Applications
Simple classification and regression
Feedforward Neural Data flows in one direction (input →
tasks, e.g., predicting house
Network (FNN) hidden → output).
prices.
Image recognition, object detection,
Convolutional Neural Uses convolutional layers to capture
facial recognition, medical
Network (CNN) spatial features.
imaging.
Recurrent Neural Processes sequential data, has memory of Time-series prediction, language
Network (RNN) previous inputs. modeling, speech recognition.
A type of RNN that solves vanishing
Long Short-Term Text generation, stock price
gradient problem, remembers long-
Memory (LSTM) prediction, language translation.
term dependencies.
Learns efficient data representation by Data compression, anomaly
Autoencoder
encoding and decoding. detection, denoising images.
Generative Adversarial Consists of generator and discriminator Image generation, deepfake
Network (GAN) networks that compete. creation, art generation.
Radial Basis Function Uses radial basis functions as activation in Function approximation, control
(RBF) Network hidden layer. systems, pattern recognition.
27
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://www.analyticsvidhya.com/blog/2022/01/introduction-to-neural-networks/
● https://www.simplilearn.com/tutorials/deep-learning-tutorial/what-is-neural-network
28
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
29
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
1. To understand the basic difference between neural network and Deep neural network
Implementation:
1. Design a deep neural network architecture using a framework such as TensorFlow or Keras.
# Preprocess data
X_train = X_train.reshape(X_train.shape[0], -1).astype('float32') / 255
X_test = X_test.reshape(X_test.shape[0], -1).astype('float32') / 255
2. Choose the number of layers, number of neurons per layer, activation functions, and regularization
techniques.
Input layer: 784 neurons (28x28 pixels flattened)
Hidden layers: 3 layers with 512, 256, and 128 neurons
Activation function: ReLU for hidden layers
Dropout: 0.2 for regularization
Output layer: 10 neurons (softmax for multi-class classification)
# Build the deep neural network
model = Sequential()
model.add(Dense(512, input_dim=784, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.2))
30
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
OUTPUT:-
Epoch 1/20
375/375 [==============================] - 6s 15ms/step - loss: 0.3754 - accuracy:
0.8901 - val_loss: 0.1642 - val_accuracy: 0.9518
Epoch 2/20
375/375 [==============================] - 5s 14ms/step - loss: 0.1510 - accuracy:
0.9557 - val_loss: 0.1213 - val_accuracy: 0.9637
Epoch 3/20
375/375 [==============================] - 5s 14ms/step - loss: 0.1085 - accuracy:
0.9671 - val_loss: 0.1028 - val_accuracy: 0.9692
...
Epoch 20/20
375/375 [==============================] - 5s 14ms/step - loss: 0.0094 - accuracy:
0.9971 - val_loss: 0.0712 - val_accuracy: 0.9813
Related Questions:
31
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
32
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://www.kdnuggets.com/2020/02/deep-neural-networks.html
● https://www.simplilearn.com/tutorials/deep-learning-tutorial/what-is-deep-learning
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
33
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
1. To understand the basic difference between neural network and Deep neural network
Implementation:
2. Choose the number of convolutional layers, pooling layers, fully connected layers, and activation
functions.
Convolutional Layers: 2 layers with filters 32 and 64, kernel size 3x3
Pooling Layers: MaxPooling 2x2 after each convolution
Fully Connected Layers: 128 neurons + output layer 10 neurons
Activation Functions: ReLU for hidden layers, Softmax for output
Dropout: 0.2 for regularization
3. Train the deep neural network on the given dataset. ( i.e. example cat vs dog, MNIST etc).
34
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
4. Evaluate the trained model's performance using metrics such as accuracy, precision, recall, and
F1-score.
# Create CNN model
model = Sequential()
Output :-
Training (example for 10 epochs)
Epoch 1/10
375/375 [==============================] - 12s 31ms/step - loss: 0.1892 - accuracy: 0.9442 -
val_loss: 0.0563 - val_accuracy: 0.9820
...
Epoch 10/10
375/375 [==============================] - 11s 30ms/step - loss: 0.0115 - accuracy: 0.9967 -
val_loss: 0.0283 - val_accuracy: 0.9910
Loss decreases quickly
Accuracy increases to ~99%
● Test Set Evaluation
Test Loss: 0.026
Test Accuracy: 0.991
● Classification Report (example)
precision recall f1-score support
Related Questions:
A convolutional layer is the core building block of a Convolutional Neural Network (CNN). It is
designed to extract features from input data, such as images, by applying filters (kernels) that detect
patterns like edges, textures, or shapes.
Key points:
Feature Description
Filter/Kernel A small matrix (e.g., 3×3 or 5×5) that slides over the input image to compute dot products.
Feature Map The output of the convolution operation showing where a feature appears in the image.
Stride How many pixels the filter moves at each step. Stride >1 reduces output size.
Padding Adding extra pixels around the input to control output size (valid or same padding).
Activation Non-linear function (like ReLU) applied to the feature map to introduce non-linearity.
Example:
If you have a 28×28 grayscale image and apply a 3×3 filter with ReLU activation, the convolutional layer
will produce a new feature map highlighting certain patterns (edges, corners, textures) in the image.
Purpose:
Automatically learn important features from raw input data.
Reduce the need for manual feature extraction.
a) Learning Rate:
Controls how much the network weights are updated during each training step.
Too high → model may overshoot minima → fail to converge.
Too low → training is slow → may get stuck in local minima.
Example: learning_rate=0.001 in Adam optimizer (commonly used).
b) Batch Size:
Number of samples processed before the model updates its weights.
Types:
o Mini-batch Gradient Descent: batch size = 32, 64, 128 (most common in CNNs)
o Stochastic Gradient Descent (SGD): batch size = 1
o Batch Gradient Descent: batch size = total number of training samples
Effect of Batch Size:
36
Mahek Gondaliya Applied Machine Learning (3171617) 220280116030
Suggested Reference:
● https://www.analyticsvidhya.com/blog/2021/05/convolutional-neural-networks-cnn/
● https://www.simplilearn.com/tutorials/deep-learning-tutorial/convolutional-neural-network
Rubric Not Acceptable (0) Below Expectation (1) Considerable (2) Acceptable (3) Score
Results Results are not Partially corrected The results are correct, The results are correct.
included. results. but not in the proper Well structured,
format.
References No references are Incorrect references are Related references are Related references are
included by the included. included but are not included and well
students. well structured. structured.
Question Not able to answer Answers are partially Answers are correct. No Answers are correct.
Answers a single question. correct. in-depth understating. Having in-depth
knowledge of concepts.
37