machine learning final manual
machine learning final manual
machine learning final manual
Now, the task is to find a line that fits best in the above scatter plot so that we can
predict the response for any new feature values. (i.e a value of x not present in the datasetThis
line is called a regression line.
PROCEDURE:
Importing required libraries like pandas & numpy for data analysis and manipulation and
seaborn & matplotlib for data visualization.
Visualizing the variables in order to interpret business/domain inferences.
Splitting the data into two sections in order to train a subset of dataset to generate a
trained (fitted) line
Rescaling the trained model: It is a method used to normalize the range of numerical
variables with varying degrees of magnitude.
1
Residual analysis of the train data tells us how much the errors are distributed across the
model. A good residual analysis will signify that the mean is centred around 0.
PROGRAM:
import numpy as np
import matplotlib.pyplot as plt
def estimate_coef(x, y):
# number of observations/points
n = np.size(x)
# mean of x and y
vector m_x =
np.mean(x)
m_y = np.mean(y)
# calculating cross-deviation and deviation about x
SS_xy = np.sum(y*x) - n*m_y*m_x
SS_xx = np.sum(x*x) - n*m_x*m_x
# calculating regression coefficients
b_1 = SS_xy / SS_xx
b_0 = m_y - b_1*m_x
return (b_0, b_1)
def plot_regression_line(x, y, b):
# plotting the actual points as scatter plot
plt.scatter(x, y, color = "m",
marker = "o", s = 30)
# predicted response vector
y_pred = b[0] + b[1]*x
# plotting the regression line
plt.plot(x, y_pred, color = "g")
# putting labels
plt.xlabel('x')
plt.ylabel('y')
# function to show plot
plt.show()
def main():
# observations / data
x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
y = np.array([1, 3, 2, 5, 7, 8, 8, 9, 10, 12])
# estimating coefficients
b = estimate_coef(x, y)
print("Estimated coefficients:\nb_0 = {} \
\nb_1 = {}".format(b[0], b[1]))
# plotting regression line
plot_regression_line(x, y, b)
if name == " main ":
main()
2
OUTPUT:
RESULT:
Thus the program to implement linear regression model was implemented and executed
successfully.
3
EX.NO:2 BINARY CLASSIFICATION MODEL DATE:
AIM:
To write a program to implement the binary classification model using python.
PROCEDURE:
Step 1: Define explanatory and target variables
Step 2: Split the dataset into training and testing sets
Step 3: Normalize the data for numerical stability
Step 4: Fit a logistic regression model to the training data
Step 5: Make predictions on the testing data
Step 6: Calculate the accuracy score by comparing the actual values and predicted values.
PROGRAM:
import numpy as np
class Perceptron(object):
""" Perceptron Classifier
Parameters
rate : float
Learning rate (ranging from 0.0 to 1.0)
number_of_iteration : int
Number of iterations over the input dataset.
Attributes:
weight_matrix : 1d-array
Weights after fitting.
error_matrix : list
Number of misclassification in every epoch(one full training cycle on the training set)
"""
def init (self, rate = 0.01, number_of_iterations = 100):
self.rate = rate
self.number_of_iterations = number_of_iterations
def fit(self, X, y):
""" Fit training data
Parameters:
4
Target values.
Returns
self : object
"""
self.weight_matrix = np.zeros(1 + X.shape[1])
self.errors_list = []
for _ in range(self.number_of_iterations):
errors = 0
for xi, target in zip(X, y):
update = self.rate * (target - self.predict(xi))
self.weight_matrix[1:] += update * xi
self.weight_matrix[0] += update
errors += int(update != 0.0)
self.errors_list.append(errors)
return self
def dot_product(self, X):
""" Calculate the dot product """
return (np.dot(X, self.weight_matrix[1:]) + self.weight_matrix[0])
def predict(self, X):
""" Predicting the label for the input data """
return np.where(self.dot_product(X) >= 0.0, 1, 0)
if name == ' main ':
X = np.array([[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0]])
y = np.array([0, 1, 1, 1, 1, 1, 1])
p = Perceptron()
p.fit(X, y)
print("Predicting the output of [1, 1, 1] = {}".format(p.predict([1, 1, 1])))
OUTPUT:
Predicting the output of [1, 1, 1] = 1
RESULT:
Thus the program for implementing binary classification model was implemented and executed
successfully.
5
EX.NO:3 CLASSIFICATION WITH NEAREST NEIGHBOURS DATE:
AIM:
To write the program for the implementation of the k-nearest neighbor algorithm
ALGORITHM:
Step 1 − For implementing any algorithm, we need dataset. So during the first step of KNN, we
must load the training as well as test data.
Step 2 − Next, we need to choose the value of K i.e. the nearest data points. K can be any
integer.
Step 3 − For each point in the test data do the following −
3.1 − Calculate the distance between test data and each row of training data with the help
of any of the method namely: Euclidean, Manhattan or Hamming distance. The most
commonly used method to calculate distance is Euclidean.
3.2 − Now, based on the distance value, sort them in ascending order.
3.3 − Next, it will choose the top K rows from the sorted array.
3.4 − Now, it will assign a class to the test point based on most frequent class of these
rows.
Step 4 − End
PROGRAM:
# Import necessary modules
from sklearn.neighbors import
KNeighborsClassifier from sklearn.model_selection
import train_test_split from sklearn.datasets import
load_iris
# Loading data
irisData = load_iris()
# Create feature and target arrays
X = irisData.data
y = irisData.target
# Split into training and test set
X_train, X_test, y_train, y_test =
train_test_split( X, y, test_size = 0.2,
random_state=42)
knn = KNeighborsClassifier(n_neighbors=7)
knn.fit(X_train, y_train)
# Predict on dataset which model has not seen before
print(knn.predict(X_test))
OUTPUT
[1 0 2 1 1 0 1 2 2 1 2 0 0 0 0 1 2 1 1 2 0 2 0 2 2 2 2 2 0 0]
6
PERFORMANCE
# Loading data
irisData = load_iris()
knn = KNeighborsClassifier(n_neighbors=7)
knn.fit(X_train, y_train)
OUTPUT:
0.9666666666666667
MODEL ACCURACY:
# Import necessary modules
from sklearn.neighbors import
KNeighborsClassifier from sklearn.model_selection
import train_test_split from sklearn.datasets import
load_iris
import numpy as np
import matplotlib.pyplot as plt
irisData = load_iris()
# Create feature and target arrays
X = irisData.data
y = irisData.target
# Split into training and test set
X_train, X_test, y_train, y_test =
train_test_split( X, y, test_size = 0.2,
random_state=42) neighbors = np.arange(1, 9)
train_accuracy =
np.empty(len(neighbors)) test_accuracy =
7
np.empty(len(neighbors)) # Loop over K
values
8
for i, k in enumerate(neighbors):
knn = KNeighborsClassifier(n_neighbors=k)
knn.fit(X_train, y_train)
# Generate plot
plt.plot(neighbors, test_accuracy, label = 'Testing dataset Accuracy')
plt.plot(neighbors, train_accuracy, label = 'Training dataset Accuracy')
plt.legend()
plt.xlabel('n_neighbors')
plt.ylabel('Accuracy')
plt.show()
OUTPUT:
RESULT :
Thus the program for the implementation of the k-nearest neighbor algorithm was verified and
executed successfully.
9
EX.NO:4 EXPERIMENT WITH VALIDATION SET AND TEST SET DATE:
AIM:
To write an experiment with validation sets and test sets for the given dataset.
PROCEDURE:
Training Dataset
The sample of data used to fit the model.The actual dataset that we use to train the model
(weights and biases in the case of a Neural Network). The model sees and learns from this data.
Validation Dataset
The sample of data used to provide an unbiased evaluation of a model fit on the training dataset
while tuning model hyperparameters. The evaluation becomes more biased as skill on the
validation dataset is incorporated into the model configuration.
Test Dataset: The sample of data used to provide an unbiased evaluation of a final model fit on
the training dataset.The Test dataset provides the gold standard used to evaluate the model. It is
only used once a model is completely trained(using the train and validation sets).
PROGRAM:
10
# Splitting dataset in 80-20 fashion .i.e.
# Testing set is 20% of total data
# Training set is 80% of total data
x_train, x_test, y_train, y_test = train_test_split(x,y,
train_size=0.8,
random_state=42)
# Training set
print("Training set x: ",x_train)
print("Training set y: ",y_train)
# Importing numpy & scikit-learn
import numpy as np
from sklearn.model_selection import train_test_split
test_size=0.2,
random_state=42)
# Testing set
print("Testing set x: ",
x_test) print("Testing set y:
", y_test)
# Importing numpy & scikit-learn
import numpy as np
from sklearn.model_selection import train_test_split
# Testing set
print("Testing set x:
",x_test) print("Testing set
y: ",y_test) print(" ")
# Validation set
print("Validation set x: ",x_val)
print("Validation set y: ",y_val)
OUTPUT:
Training set x: [[ 0 1]
[14 15]
[ 4 5]
[ 8 9]
[ 6 7]
[12 13]]
Training set y: [0, 7, 2, 4, 3, 6]
Testing set x: [[ 2 3]
[10 11]]
Testing set y: [1, 5]
Training set x: [[ 0 1 2]
[21 22 23]
[ 6 7 8]
[12 13 14]
[ 9 10 11]
12
[18 19 20]]
Training set y: [0, 7, 2, 4, 3, 6]
RESULT:
Thus the program for the implementation of an experiment with validation sets and test sets for
the given dataset was verified and executed successfully.
13
EX.NO:5 K-MEANS CLUSTERING DATE:
AIM:
To write a program for the implementation of the Kmeans to the given dataset.
PROCEDURE:
Step-1: Select the number K to decide the number of clusters.
Step-2: Select random K points or centroids. (It can be other from the input dataset).
Step-3: Assign each data point to their closest centroid, which will form the predefined K
clusters.
Step-4: Calculate the variance and place a new centroid of each cluster.
Step-5: Repeat the third steps, which means reassign each datapoint to the new closest centroid
of each cluster.
Step-6: If any reassignment occurs, then go to step-4 else go to FINISH.
Step-7: The model is ready.
PROGRAM
from sklearn.cluster import KMeans
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from matplotlib import pyplot as plt
from sklearn.datasets import load_iris
%matplotlib inline
iris = load_iris()
df = pd.DataFrame(iris.data,columns=iris.feature_names)
df.head()
OUTPUT:
14
df['flower'] = iris.target
df.head()
OUTPUT:
km = KMeans(n_clusters=3)
yp = km.fit_predict(df)
yp
OUTPUT:
df['cluster'] = yp
15
df.head(2)
16
OUTPUT:
df.cluster.unique()
OUTPUT:
df1 =
df[df.cluster==0] df2
= df[df.cluster==1]
df3 = df[df.cluster==2]
17
sse = []
k_rng = range(1,10)
for k in k_rng:
km = KMeans(n_clusters=k)
km.fit(df)
sse.append(km.inertia_)
plt.xlabel('K')
plt.ylabel('Sum of squared error')
plt.plot(k_rng,sse)
OUTPUT:
RESULT :
Thus the program for the implementation of the Kmeans to the given dataset was verified and
executed successfully.
18
EX.NO:6 NAIVE BAYES CLASSIFIER DATE:
AIM:
To implement a program for Naïve Bayes model
NAIVE BAYES CLASSIFIER ALGORITHM
Naive Bayes is among one of the very simple and powerful algorithms for classification
based on Bayes Theorem with an assumption of independence among the predictors.
The Naive Bayes classifier assumes that the presence of a feature in a class is not
related to any other feature.
Naive Bayes is a classification algorithm for binary and multi-class classification
problems.
Bayes Theorem
Based on prior knowledge of conditions that may be related to an event, Bayes
theorem describes the probability of the event
conditional probability can be found this way
Assume we have a Hypothesis(H) and evidence(E),
According to Bayes theorem, the relationship between the probability of
Hypothesis before getting the evidence represented as P(H) and the probability
of the hypothesis after getting the evidence represented as P(H|E) is:
P(H|E) = P(E|H)*P(H)/P(E)
19
Step 4: Trying all together
Finally, we tie to all steps together and form our own model of Naive Bayes Classifier.
PROGRAM:
X, Y = zip(*in_time)
X2, Y2 = zip(*too_late)
bar_width = 0.9
plt.bar(X, Y, bar_width, color="blue", alpha=0.75, label="in time")
bar_width = 0.8
plt.bar(X2, Y2, bar_width, color="red", alpha=0.75, label="too late")
plt.legend(loc='upper right')
plt.show()
in_time_dict = dict(in_time)
too_late_dict = dict(too_late)
def catch_the_train(min):
s = in_time_dict.get(min, 0)
if s == 0:
return 0
else:
m = too_late_dict.get(min,
0) return s / (s + m)
20
OUTPUT:
-1 0
0 1.0
1 1.0
2 1.0
3 1.0
4 1.0
5 1.0
6 0.6
7 0.4375
8 0.25
9 0.15
10 0.14285714285714285
11 0.11764705882352941
12 0
RESULT:
Thus the program to implement naïve bayes classifier hass been verified and executed
successfully.
21
Ex.No:7. MINI PROJECT. DATE:
ABSTRACT
1. INTRODUCTION
Deep learning is a subset of machine learning and artificial intelligence (AI) that mimics how a
human brain functions, and it allows computers to address complex patterns that create new insights and
solutions. If you’ve used technology like a digital assistant on your phone, received a text alerting you of
credit card fraud, or ridden in a self-driving car, you’ve used deep learning. A deep learning model is a
compilation of nodes that connect and layer in neural networks, much like the human brain. These networks
pass information through each layer, sending and receiving data to identity patterns. Deep learning models
use different types of neural networks to achieve specific solutions.
Deep learning models typically have three or more layers of neural networks to help process data.
These models have the ability to process data that’s unstructured or unlabeled, creating their own methods
for identifying and understanding the information without a person telling the computer what to look for or
solve. Because deep learning models can identify both higher and lower-level information, they can take
data sets that are difficult to understand and create simpler, more efficient categories. This ability allows the
deep learning model to grow more accurate over time. Deep learning is the key to the advancement of
artificial intelligence. In this article, you can learn about deep learning models, the different types of deep
22
learning models, and careers in the field. Two data scientists use a tablet and discuss the deep learning
models that they created. Deep learning is a subset of machine learning and artificial intelligence (AI) that
mimics how a human brain functions, and it allows computers to address complex patterns that create new
insights and solutions. If you’ve used technology like a digital assistant on your phone, received a text
alerting you of credit card fraud, or ridden in a self-driving car, you’ve used deep learning. A deep learning
model is a compilation of nodes that connect and layer in neural networks, much like the human brain.
These networks pass information through each layer, sending and receiving data to identity patterns. Deep
learning models use different types of neural networks to achieve specific solutions. Skills you'll
build:Recurrent Neural Network, Tensorflow, Convolutional Neural Network, Artificial Neural Network,
Transformers, Backpropagation, Python Programming, Deep Learning, Neural Network Architecture, Facial
Recognition System, Object Detection and Segmentation, hyperparameter tuning, Mathematical
Optimization, Decision-Making, Machine Learning, Inductive Transfer, MultiTask Learning, Gated
Recurrent Unit (GRU), Natural Language Processing, Long Short Term Memory (LSTM), Attention
Models
23
Natural language processing: This is a computer’s ability to understand text copy. You can use natural
language processing for translation services, chatbots, and keyword indexing.
Deep learning models work by interacting with immense sets of data and extracting patterns and
solutions from them through learning styles similar to what humans naturally do. They use artificial neural
networks to parse and process data sets. The networks operate using algorithms, which provide the
opportunity for the computer to adapt and learn on its own without needing a human to guide the learning.
Each type of deep learning model applies to different uses, but they all have the same learning and
training process in common. To train a deep learning model, huge sets of data need to feed into the network.
This information passes from neuron to neuron, allowing the computer to analyze and understand the data as
it moves through the network. Deep learning models are scalable and fast, so they have the ability to handle
whatever data sets you might want to be processed without needing a lot of setup or maintenance
Pneumonia impacts all the elderly and young people every where. With the high growth in the
popularity of neural networks, engineers and researchers have been able to find state-of-the- art products for
computer vision. Artificial Intelligence helps us to automate analysis techniques, which is only possible now
because of the technology of DeepLearning. Exposure to Pneumonia is quite high for many people, mainly
in economically underdeveloped and developing countries where the majority are deprived of a nutritious
diet. The World Health Organization states that more than 4 million untimely deaths per year occur from
diseases caused by air pollution.
The purpose of this project is to build an AI network ,which takes the pixel values as input for
a given X-Ray image and then proceeds to perform linear operations and activations on each of
them .Then by taking all the above operations, and then multiplying them with each layer within the
neural network, and the number of nodes. Suddenly you have millions of operations. The objective
and automated detection of pneumonia represents a serious challenge in medical imaging, because the
signs of the illness are not obvious in CT or X-ray scans. Further on, it is also an important task, since
millions of people die of pneumonia every year. The main goal of this paper is to propose a solution
for the above mentioned problem, using a novel deep neural network architecture. The proposed
novelty consists in the use of dropout in the convolutional part of the network. The proposed method
was trained and tested on a set of 5856 labeled images available at one of Kaggle’s many medical
imaging challenges. The chest X-ray images (anterior-posterior) were selected from retrospective
cohorts of pediatric patients, aged between one and five years, from Guangzhou Women and
Children’s Medical Center, Guangzhou, China. Results achieved by our network would have placed
first in the Kaggle competition with the following metrics. A four-class classification of breast CT
images based on two-dimensional fractional Fourier entropy features, and obtained a 92.3% averaged
score.
24
2. LITERATURE REVIEW
Wang et al. [18] deployed a deep rank-based average pooling network that combined an n-conv rank-
based average pooling module with a CNN model inspired by the VGG network, reaching an average
score of 95.5% in a study elaborated on 1164 CT scans of 521 subjects.
Horry et al. [19] performed a comparative study of imaging modalities within the pneumonia detection
framework and found that pneumonia can be best detected from ultrasound scans. Rajaraman et al. [20]
presented a framework in which various CNN models deployed through transfer learning were involved
in ensemble learning. Their ensembles were trained using 16,700 CXR images originating from 4 public
databases, and achieved various accuracy rates between 94% and 99%.
Singh and Yow [21] proposed an interpretable deep learning neural network approach based on two
existing models, ProtoPNet and NP-ProtoPNet, and achieved an accuracy of 87.27%.
Most of the above presented solutions deploy transfer learning, meaning that the networks were
previously trained on images not related to pneumonia. There are several machine vision applications that
use CNNs built from scratch which proved that a smaller architecture may obtain finer accuracy than
several pretrained larger models deployed via transfer learning. In this study we propose to build a novel
CNN architecture to provide an accurate solution to the problem of pneumonia detection. The main
novelty consists in the fact that our CNN model uses dropout in the convolutional part of the network,
unlike the majority of existing architectures, which use dropout exclusively in the fully connected part of
the network where the main part of the parameters is trained. This paper proves that the proposed model
can provide accurate classification despite the reduced number of trained parameters and can even benefit
from this property in terms of efficiency.
25
3. SOFTWARE REQUIREMENT SPECIFICATION
This software requirement specification (SRS) report expresses a complete description about
the proposed System.This document includes all the functions and specifications with their
explanations to solve related problems.
SOFTWARE REQUIREMENTS
● Google Collab
● TensorFlowv2.7.0
● CUDAv11.5
● CuDNNv8.3
HARDWAREREQUIREMENTS
● 8GBRAM
● i5intelcore/AMDRyzen5
● CUDAEnabledGeForceGTX1650
● 256SSDand1TBHDD
Project Purpose
The Purpose of the project is to develop a system To provide an efficient and effective solution over
the conventional way of detecting pneumonia disease using CNN
Project Scope
26
Assumptions and Dependencies
• Assumptions:
3. User-Friendly.
• Dependencies:
1. All necessary software is available for implementing and use of the system.
2. The proposed system would be designed, developed and implemented based on the software
requirements specifications document.
3. End users should have basic knowledge of computers and we also assure that the users will be given
software training documentation and reference material.
FUNCTIONAL REQUIREMENT
System Feature1(Functional Requirement)
Functional requirement describes features, functioning, and usage of a product/system or
software from the perspective of the product and its user.Functionalrequirementsarealsocalled
functional specifications where the synonym for specification is design. Provide User friendly Interface
and Interactive as per standards.
NON-FUNCTIONAL REQUIREMENT
Performance Requirements
• High Speed: - System should process requested tasks in parallel for various actions to give a quick
response. Then the system must wait for process completion.
• Accuracy:-Systemshouldcorrectlyexecutetheprocessanddisplaytheresultaccurately. System output
should be in user required format.
• Safety Requirements:
The data safety must been sured by arranging for a secure and reliable transmission media.
Security Requirements
1. Runtime System Qualities: Runtime System Qualities can be measured as the system executes.
2. Functionality:The abilityof the system to do the work for which it was intended.
3. Performance:The responsetime,utilization,and through put behavior of the system.Not to be
confused with human performance or system delivery time.
4. Security: A measure of system’s ability to resist unauthorized attempts at usage or behavior
modification, while still providing service to legitimate users.
5. Availability: (Reliability quality attributes fall under this category) the measure of time that the
system is up and running correctly; the length of time between failures and the length of time
needed to resume operation after a failure.
6. Usability:The ease of use and of training the end users of the system.Subqualities:learn ability,
efficiency, affect, helpfulness, control.
7. Interoperability:The ability of two or more systems to cooperate at runtime.
SYSTEM REQUIREMENT
ANALYSISMODELS:(SDLCMODELTOBEAPPLIED)
One of the basic notions of the software development process is SDLC models which stands for
Software Development Life Cycle models.SDLC is a continuous process,which starts from the
moment,when its made adecision to launch the project,and it ends at the moment of its full remove
from the exploitation. There is no one single SDLC model. They are divided into main groups, each
with its features and weaknesses. Evolving from the first and oldest waterfall SDLC model, their
variety significantly expanded.
The SDLC models diversity is pre determined by the wide number of product types starting with a web
application development to a complex medical software. And if you take one of the SDLC models
mentioned below as the basis in any case,its hould be adjusted to the features of the product, project,
and company.
The most used, popular and important SDLC models are given below:
1. Waterfall Model
2. Iterative Model
3. Spiral Model
4. V-shaped Model
5. Agile Model
28
Waterfall Model:
Water fall is a cascade SDLC model,in which the development process looks like the flow,moving
step by step through the phases of analysis, projecting, realization, testing, implementation, and support.
This SDLC model includes gradual execution of every stage completely. This process is strictly documented
and predefined with features expected to every phase of this software development life cycle model.
Figure3.1:WaterfallModel
Each software development life cycle model starts with the analysis, in which the
stakeholdersoftheprocessdiscusstherequirementsforthefinalproduct.Thegoalofthisstageis the detailed
definition of the system requirements. Besides, it is needed to make sure that all the process
participants have clearly understood the tasks and how every requirement is going to be
implemented.Often,the discussion involves the QA specialists who can interfere the process with
additions even during the development stage if it is necessary.
29
The programming by itself assumes four stages:-
• Algorithm development
• Source code writing
• Compilation
• Testing and debugging
4. Testing
The testing phase includes the debugging process. All the code flaws missed during the
development are detected here, documented and passed back to the developers to fix.The testing
process repeats until all the critical issues are removed and software work is stable.
5. Deployment
When the program is finalised and has no critical issues it is time to launch it for the end users.
After the new program version release,the tech support team joins.This department provides user
feedback; consult and support users during the time of exploitation. Moreover, the update of selected
components is included in this phase, to make sure,that the software is up-to-date and is invulnerable to
a security breach.
DESIGN AND MODELLING OF SYSTEM
Unified Modelling Language(UML)is an a logousto the blueprints used in other fields and consists
of different types of diagrams. In the aggregate, UML diagrams describe the boundary, structure, and
behaviour of the system and the objects within it.
Following UML diagrams have been designed for the project:
1. Use Case Diagram
2. Class Diagram
3. Sequence diagram
4. Activity Diagram
5. State Diagram
Use Case Diagram
Use case diagrams are usually referred to as behaviour diagrams used to describe a set of
actions that some system or systems should or can perform in collaboration with one or more external
users of the system.Each use case should provide some observable and valuable result to the actors or
other stakeholders of the system. Figure 1 shows the use case diagram of the system.
30
Use Case Diagram
Class Diagram
A class diagram is an illustration of the relationships and source code dependencies among
classes in the Unified Modelling Language (UML). In this context, a class defines the methods and
variables in an object, which is a specific entity in a program or the unit of code representing that
entity. Figure 2 shows the class diagram of the project, the various classes used in the diagram are
user, student, teacher, Image, Cloud, Face Recognition.
Fig4.2.ClassDia
gram
31
Sequence Diagram
Sequence diagrams are sometimes called event diagrams or event scenarios. A sequence
diagram shows, as parallel vertical lines (lifelines), different processes or objects that live
simultaneously, and, as horizontal arrows, the messages exchanged between them, in the order in which
they occur
The activity diagram is an other import and diagramin UML to describe the dynamic aspects of
the system.Anactivity diagramis basically a flow chartto represent the flow from one activity to another
activity. The activity can be described as an operation of the system.
Fig4.4.Activity Diagram
32
State Diagram
A statediagram, some times known as a state machine diagram,is a type of behavioral diagram in
theUnified Modelling Language (UML) that shows transitions between various objects.
Fig4.5.State Diagram
33
5. ALGORITHM AND METHODS
Data Acquisition
The proposed database used to evaluate the performance of the model contains a total of 5863 X-
ray photos from the Kaggle.
(a) (b)
Fig5.1 Examples from the data set.(a) normal cases (b) pneumonia cases
Data Pre-processing
The strategies used throughout this paper are listed in Table 2. In our study, rescale is a value
by which we will multiply the data be fore any other processing.Our original images consist of RGB
coefficients in the 0-255, but such values would be too high for our models to process (given a typical
learning rate), so we target values between 0 and 1 instead of by scaling with a 1/255. factor. shear
range is for randomly applying shearing transformations zoom range is for randomly zooming inside
pictures, horizontal flip is for randomly flipping half of the images horizontally --relevant when there
are no assumptions of horizontal asymmetry (e.g. realworld pictures)
Data pre-processing techniques used in this study
34
Proposed Network
In this study, we designed a CNN model to extract the features of chest X-ray images and use
those features to detect if a patient suffers from pneumonia. In Our CNN Architecture, we began it with
a lower filter value of 32 and increased it layer-wise. Constructed the model with a layer of Conv2D
followed by a layer of Carpooling. The kernel size is preferred to be an odd number like 3x3.
Tanh,ReLU,etc.can be used for activation function,butReLU is the most preferred activation function.
input shape takes in image width & height with the last dimension as a color channel. then we Flatten
the input after CNN layers and added ANN layers.
f(x)=max(0,x)
S(x)=Sigmoid f(x)
= ReLU
Used activation function as Soft Max for the last layers (ANN Layers) also defined units as the total
number of classes and used sigmoid for binary classification and set unit to 1.
35
operations.The first layer filters the image with several convolution kernels and returns “feature maps”,
which are then normalized (with an activation function) and/or resized.
Image
Convolvedfeature Fig5.4.1ConvLayer
(featureMap)
Pool Layers
The second block is not characteristic of a CNN: it is in fact at the end of all the neural
networks used for classification. The input vector values are transformed (with several linear
combinations and activation functions) to return a new vector to the output. This last vector contains as
many elements as there are classes:element Irepresents the probability that the image belongs to class
I.Each element is there fore between 0 and 1,and the sum of all is worth 1.These probabilities are
calculated by the last layer of this block (and therefore of the network), which uses a Sigmoid function
(binary classification) or a RELU function (multi-class classification) as an activation function.
36
between inputs and outputs. Common activation functions include the sigmoid, ReLU, and tanh
functions.
ReLU
Rectified linear unit is most widely used and preferred activation function right now Which
ranges from 0 to infinity,All the negative values are converted into zero.
f(x)=max(0,x)
Sigmoid
The sigmoid function also called a logistic function. having a characteristic that can take any
real value and map it to between 0 to 1.It decides which value to pass as output and what not to pass.
VGG16 Model
VGG16 is a popular convolutional neural network architecture for image classification tasks.It
consists of 16 layers,including 13 convolutional layers and 3 fully connected layers.The convolutional layers
use small 3x3 filters with a stride of 1 and are followed by max pooling layers. The fully connected layers at
the end of the network perform the classification task. The VGG16 model has achieved state-of-the-art
performance on several image recognition benchmarks, making it a popular choice for computer vision
tasks.
Data Acquisition
Fig6.1.1Mount Drive
37
Fig6.1. Import Train and Test Data
Data Augmentation
38
Fig6.2.3Augmented Dataset images
We have analyzed the performance of these bellow CNN architectures namely;Alex Net, ResNet-50, and
VGG Net-16. [3]
39
Fig6.3 ResNet-50 Fig6.4 AlexNet
Fig6.5 VGG16
Image pre-processing
We'll use an Image Augmentation approach to artificially boost the size of the image training dataset. Image
Augmentation increases the size of the data set by creating a modified version of the existing training set
photos,which increases data set variation and, as a result,improves the model's ab
40
7. Confusion Matrix
Let’s interpret the output of the confusion matrix. The upper left (TP) denotes the number of
images correctly predicted as normal cases and the bottom right (TN) denotes the correctly predicted
number of images as cases of pneumonia. As Pneumonia case, the upper right denotes the number of
incorrectly predicted images but were actually normal cases and the lower left denotes the number of in
correctly predicted Normal case images but were actually Pneumonia case.
Mathematical Model
Fig.7.3Predicted Images
41
● This provides you a percentage estimate of the individual image,which you may load straight
from your hard drive by specifying its path.
● After importing the image as we did previously,we must recreate all of the data pretreatment
procedures in order to input the test set into the model and obtain a forecast.
Importing the tensorflow.keras.preprocessing.image class is required for pre-processing.
● Import an image with dimensions of (500,500) and a gray scale color channel.
UserInterface
Using Flask Flask is a micro web framework written in Python that allows developers to quickly
build web applications. It provides simple and easy-to-use tools and libraries for routing requests,
handling HTTP requests and responses,and rendering templates.Flask is known for its flexibility and
extensibility, making it a popular choice among developers for building web applications.
Fig.7.4FrontendUserInterfacewith Flask
42
8. CONCLUSION
This study describes a CNN-based model aiming to diagnose pneumonia on a chest X-ray image
set. The contributions in this paper are listed as follows. We designed a CNN model to extract the features
from original images or previous feature maps, which contained only six layers combining ReLU
activation function, drop operation, and max-pooling layers. The results of the obtained accuracy rate of
92.07% and precision rate of 91.41%,shows that our proposed model performs well In comparison to state-
of-the-art CNN model architectures.To illustrate the performance of our proposed model, several
comparisons of different input shapes and loss functions were provided.
In the future, we will continue the research to explore more accurate classification architectures
to diagnose two types of pneumonia, viruses, and bacteria. According to the description discussed
above,the CNN-based model is apromising method to diagnose the disease through X-rays.
43
9. BIBLIOGRAPHY
[1] Vandecia Fernandes et al., “Bayesian convolutional neural network estimation for pediatric
pneumonia detection and diagnosis”,Computer Methods and Programs in Biomedicine, Elsevier,
2021
[5] Md. Jahid Hasan et al., “Deep Learning-based Detection and Segmentation of COVID-19 &
Pneumonia on Chest X-ray Image”, 2021 International Information and Communication Technology
for Sustainable Development (ICICT4SD), 27-28 February 2021
[6] https://www.kaggle.com/paultimothymooney/chest-xray-pneumonia
[7] LeCun, Y.; Boser, B.; Denker, J.S.; Henderson, D.; Howard, R.E.; Hubbard, W.; Jackel, L.D. Back
propagation applied to hand written zip code recognition.NeuralComput.1989,1,541–551.
[8] Krizhevsky, A.; Sutskever, I.; Hinton, G.E. Imagenet classification with deep convolutional neural
networks. Adv. Neural Inf. Process. Syst. 2012, 25, 1097–1105.
[10] R. R. Selvaraju, M. Cogswell, A. Das, R. Vedantam, D. Parikh and D. Batra, "Grad-CAM: Visual
Explanations from Deep Networks via Gradient-Based Localization," 2020 IEEE International
Conference on Computer Vision (ICCV), Venice, 2020, pp. 618-626.
44
45