Artifical Intelligence Coursework Report
Artifical Intelligence Coursework Report
Artifical Intelligence Coursework Report
Networks
55-700241 Applicable Artificial Intelligence
BY
AMAL THOMAS JOSE
30046158
Data Classification using Neural Networks
Table of Contents
1. INTRODUCTION..............................................................................................................2
2. REQUIREMENT ANALYSIS..........................................................................................2
3. DESIGN CONSIDERATIONS.........................................................................................3
4. IMPLEMENTATION AND TESTING.............................................................................3
4.1 IMPELEMENTATION...............................................................................................3
(a) Data Analysis:..........................................................................................................3
(b) Data Standardization and Normalization:................................................................4
4.2 TESTING....................................................................................................................8
5. EVALUATION/CONCLUSION.....................................................................................21
6. REFERENCES.................................................................................................................21
7. APPENDIX......................................................................................................................22
1
Data Classification using Neural Networks
1. INTRODUCTION
2. REQUIREMENT ANALYSIS
The task to be done is classification of data using a Neural network to detect heart
disease from a set of cleaned up data. Using backpropagation algorithm, it is possible
to achieve the required results. Computational or programming software’s like
MATLAB or Python is generally used to solve neural networks problems.
MATLAB version R2021a is used in this coursework to design, train and simulate the
neural network to an accuracy of 90 percentage. The system will be designed in such
a way that it will be reliable, robust, and accurate to work and process any given
dataset to satisfaction.
Input parameters and the corresponding target parameters are used to train a network
until it can approximate a function. Networks with biases, a sigmoid layer, and a
linear output layer can approximate any function with a finite number of
discontinuities. Standard backpropagation is a gradient descent algorithm, in which
the network weights are moved along the negative of the gradient of the performance
function.
The requirement or aim of this coursework is to design, implement and obtain a
system that will be able to distinguish different classes (0, 1 and 2) from a set of 13
known inputs, which contains different parameters.
2
Data Classification using Neural Networks
3. DESIGN CONSIDERATIONS
The neural network is designed using MATLAB, to build an efficient, accurate neural
network, three main steps are followed:
Design
Training
Simulation
The first and foremost step in designing a neural network is to define whether the
given input data is linearly separable or not. Because depending upon this we decide
whether to use “perceptron” or “feedforwardnet” command, if the data is linearly
separable “perceptron” command is used and if not, we use “feedforwardnet”. This
process is done by plotting a graph using the inputs and checking if a straight line can
separate them.
The second important design consideration is to identify how many hidden layers and
nodes are needed to test a given dataset to gain an accurate network.
The third consideration is to decide which transfer function (tansig, logsig, purlin),
type of data divider function (dividetrain, dividerand, divideblock etc) and training
function (traingd, trainlm etc) to use to obtain a robust and desirable network.
4.1 IMPELEMENTATION
Neural networks are data-driven i.e., it depends on the data given. The given input (x)
dataset contains an array of elements of order (297 x 13) and the response or target (t)
is of order (297 x 1) array. The aim to build and train a neutral network as close to the
target. So, as mentioned in design consideration, the first step is to design the
network.
4.1.1. Design:
(a) Data Analysis:
Using “find” command in MATLAB, it is possible to plot a graph between class 0,
class 1, and class 2.
Where, class 0: No heart disease.
Class 1: Mild heart disease.
Class 2: Severe heart disease.
By using MATLAB code figure, (plot), we can separate classes 0,1 &2 and define the
nature of data, i.e.., linearly separable or not.
3
Data Classification using Neural Networks
4
Data Classification using Neural Networks
The only way to understand which dataset is better, is to try building the neural
network using different datasets. In this coursework, to understand how neural
network depends on data, three case studies will be conducted, with raw data,
5
Data Classification using Neural Networks
normalized data, and standardized data to see which will train the dataset to best
accuracy.
4.1.2. Training:
6
Data Classification using Neural Networks
7
Data Classification using Neural Networks
8
Data Classification using Neural Networks
4.1.3 Simulation:
Once the neural network is designed and trained using the set function, the
next step is to simulate the network to see how well the network learned the
data during the training. The MATLAB command “sim” is used to simulate
the neural network.
Eg: mynet = sim(mynet, inputs);
4.2TESTING
We use three cases of data (raw data, standardized data, and normalized data)
to train the neural networks and results of each is recorded to identify which
form of dataset will give the most accurate neural network.
(a) Case 1: Design, train and simulate a neural network using raw data.
In this case, we use the raw dataset for training and testing, also the results will be
recorded to measure the accuracy of network obtained using this dataset.
Step1: Design
9
Data Classification using Neural Networks
Step 2: Train
We will also change the divdeFcn, transferFcn and trainFcn as discussed in Table
1. MATLAB codes is in appendix [1].
After changing the function, the network should be reinitialised using the
command.
mynet = “init(mynet)”,
10
Data Classification using Neural Networks
11
Data Classification using Neural Networks
12
Data Classification using Neural Networks
Step 3: Simulation
Once the neural network is trained using the algorithm, we will simulate the
network using code “result =sim (mynet, x);”
To check the accuracy of the network, we will create a truth table using predicated
class and true class with a for loop. The logic used is shown below and in
appendix [1].
Results = sim(mynet,x)
for i=1: numel(t)
if results(i)>1.5
results(i)=2;
elseif results(i)<1.5 && results(i)>=0.5
results(i)=1;
else
results(i)=0;
end
13
Data Classification using Neural Networks
The values in blue coloured squares along the diagonals on the confusion chart
is the accurate values and hence.
151+74 +30
accuracy= =0.858 ≅ 85.8 %
297
(b) Case 2: Design, train and simulate a neural network using standardized data.
In this case, we use the standardized dataset for training and testing, also the
results will be recorded to measure the accuracy of network obtained using this
dataset.
Step1: Design
We use the code “mynet = feedforward ([120 40 60 80]);”, thus we get our neural
network with four hidden layers as shown in figure.
Step 2: Train
14
Data Classification using Neural Networks
We will also change the divdeFcn, transferFcn and trainFcn as discussed in Table
1. MATLAB codes is in appendix [2].
After changing the function, the network should be reinitialised using the
command.
“mynet=init(mynet)”,
15
Data Classification using Neural Networks
16
Data Classification using Neural Networks
17
Data Classification using Neural Networks
Once the neural network is trained using the algorithm, we will simulate the
network using code “result =sim (mynet, xs);”
To check the accuracy of the network, we will create a truth table using predicated
class and true class with a for loop. The logic used is shown below and in
appendix [2].
Results = sim(mynet,xn)
for i=1: numel(t)
if results(i)>1.5
results(i)=2;
elseif results(i)<1.5 && results(i)>=0.5
results(i)=1;
else
results(i)=0;
end
18
Data Classification using Neural Networks
147+77+30
accuracy = =0.855 ≅ 85.5 %
297
(c) Case 3: Design, train and simulate a neural network using normalized data.
In this case, we use the normalized dataset for training and testing, also the results
will be recorded to measure the accuracy of network obtained using this dataset.
Step1: Design
Step 2: Train
We will also change the divdeFcn, transferFcn and trainFcn as discussed in Table
1. MATLAB codes is in appendix [3].
After changing the function, the network should be reinitialised using the
command.
“mynet=init(mynet)”,
19
Data Classification using Neural Networks
20
Data Classification using Neural Networks
21
Data Classification using Neural Networks
Step 3: Simulation
22
Data Classification using Neural Networks
Once the neural network is trained using the algorithm, we will simulate the
network using code “result =sim (mynet, xn);”
To check the accuracy of the network, we will create a truth table using predicated
class and true class with a for loop. The logic used is shown below and in
appendix [3].
Results = sim(mynet,xn)
for i=1: numel(t)
if results(i)>1.5
results(i)=2;
elseif results(i)<1.5 && results(i)>=0.5
results(i)=1;
else
results(i)=0;
end
23
Data Classification using Neural Networks
5. EVALUATION/CONCLUSION
In this coursework, we did data classification by building neural networks. They were
designed, implemented, and tested under three different cases. The table below shows
the accuracy and concluding results of neutral networks in each case.
Dataset Gradient value Performance Epochs Accuracy
x 0.036658 0.10987 5000 85.8
xs 0.036285 0.10790 5000 85.5
xn 0.035478 0.092901 5000 87.5
Table 2: Results
From the above table it is clear that accuracy of a neural network depends on the data
set provided i.e.., it is data-driven. From the graph we can see that the curve is
critically damped and will not converge but will lean towards convergence (small
errors). From performance curves, we can observe the network is very sensitive to the
type and quality of data.
In conclusion, we can say that, in this coursework the normalized data set have more
accuracy compared to the other cases and have an efficiency of 87%. By changing
algorithms and other parameters, it is still possible to obtain the 90% benchmark
accuracy.
6. REFERENCES
24
Data Classification using Neural Networks
7. APPENDIX
MATLAB CODES
load cleveland_heart_disease_dataset_labelled.mat
% Data Analysis
mynet = train(mynet,x,t)
mynet.layers{1}.transferFcn = 'logsig';
mynet.layers{2}.transferFcn = 'logsig';
mynet.layers{3}.transferFcn = 'logsig';
mynet.layers{4}.transferFcn = 'logsig';
mynet.divideFcn = 'dividetrain'
mynet.trainFcn = 'traingd';
mynet.trainParam.epochs =5000;
mynet = init(mynet);
mynet = train(mynet,x,t)
results = sim(mynet,x)
for i=1: numel(t)
if results(i)>1.5
results(i)=2;
elseif results(i)<1.5 && results(i)>=0.5
results(i)=1;
else
results(i)=0;
end
end
confusionchart(results, t)
25
Data Classification using Neural Networks
Class0_idx = find(t==0);
Class1_idx = find(t==1);
Class2_idx = find(t==2);
%Standardization
xs = normalize(x)
figure, plot(xs(Class0_idx,:)','y'),title('Standardized Data')
hold on
plot(xs(Class1_idx,:)','b')
plot(xs(Class2_idx,:)','r')
hold off
mynet = train(mynet,xs,t)
mynet.layers{1}.transferFcn = 'logsig';
mynet.layers{2}.transferFcn = 'logsig';
mynet.layers{3}.transferFcn = 'logsig';
mynet.layers{4}.transferFcn = 'logsig';
mynet.divideFcn = 'dividetrain'
mynet.trainFcn = 'traingd';
mynet.trainParam.epochs =5000;
mynet = init(mynet);
mynet = train(mynet,xs,t)
results = sim(mynet,xs)
for i=1: numel(t)
if results(i)>1.5
results(i)=2;
elseif results(i)<1.5 && results(i)>=0.5
results(i)=1;
else
results(i)=0;
end
end
confusionchart(results, t)
26
Data Classification using Neural Networks
Class0_idx = find(t==0);
Class1_idx = find(t==1);
Class2_idx = find(t==2);
%Normalization
xn = normalize(x,'range')
figure, plot(xn(Class0_idx,:)','y'), title('Normalized Dataset')
hold on
plot(xn(Class1_idx,:)','b')
plot(xn(Class2_idx,:)','r')
hold off
mynet = train(mynet,xn,t);
mynet.layers{1}.transferFcn = 'logsig';
mynet.layers{2}.transferFcn = 'logsig';
mynet.layers{3}.transferFcn = 'logsig';
mynet.layers{4}.transferFcn = 'logsig';
mynet.divideFcn = 'dividetrain'
mynet.trainFcn = 'traingd';
mynet.trainParam.epochs =5000;
mynet = init(mynet);
mynet = train(mynet,xn,t)
results = sim(mynet,xn)
for i=1: numel(t)
if results(i)>1.5
results(i)=2;
elseif results(i)<1.5 && results(i)>=0.5
results(i)=1;
else
results(i)=0;
end
confusionchart(results, t)
27