Question
Hello, I would like some help with matlap please. I was given this script and I would like a matlab MLP which follows the same
Hello, I would like some help with matlap please. I was given this script and I would like a matlab MLP which follows the same inputs and outputs of this question so that I can see an example of how MLP's work in matlab!
It takes in a big excel sheet with 3 classes and then it takes another for testing. It then outputs 3 outputs. I just need a script that will run better than this base one!
% ########################## Assignment 5 base script
% needs to be in the same directory as the data files
numClass = 3;
data = uiimport('train.csv');
size(data.train)
input = data.train;
size(input)
input(:,43 ) = []; % Remove class labels
size(input)
d = data.train(:,43); % Stroe class labels in d
x = input';
d = d';
% Get the class distribution in training set (display purposes only)
nc = zeros(1,numClass)
for i = 1:numClass
nc(1,i) = sum(d(:) == i);
disp(sprintf('Class %d : %d', i, nc(1,i)))
end
% Create binary matrix of class labels ************************************
% There are now three outputs, i.e. one output per class
d = dummyvar(d);
d = d';
% Normalize inputs ********************************************************
[xn, xs] = mapminmax(x); % normalize inputs
% % Basic linear network, should give ADR of ~0.5 using train.csv, and ~0.59 using trainOversampled.csv ***
maxlr = 0.40*maxlinlr(xn); % initialize learning rate and network weights
net1 = newlin(minmax(xn), numClass, [0], maxlr); % one output for each class
net1.trainParam.epochs = 6000;
[net1,tr] = train(net1,xn,d);
% Establish output of neuron and plot the confusion matrix ****************
y = sim(net1,xn);
plotconfusion(d,y);
% Import the test data (no label information) *****************************
data = uiimport('test.csv');
input = data.test;
x = input';
% Reapply the normalization estimated on the training set *****************
xnTest = mapminmax('apply', x, xs);
% Perform forward pass through the network under TEST data ****************
y = sim(net1, xnTest);
csvwrite('B00708156-test.csv',y); % Save network outputs
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started