MATLAB Answers

How to Apply PCA Corrrect way

2 views (last 30 days)
I have data 322*91 .
322*88 is my input , my features. 322*3 my outputs, my targets.
My neural network result is not good because 88 features is more according to 322 datas.
Data should be more to get good accuracy.
But I have no chance to increase it.
So I want to apply PCA to decrease 88 features but I couldn't manage to apply it in correct way.
How can I do that?
When I write the code newinput=pca(input)
it decreases row number and gives 88*88 .
I need to keep row number (322) and decrease only 88 numbers.
Codes are below for neural network
And data is attached.
% Solve a Pattern Recognition Problem with a Neural Network
% Script generated by Neural Pattern Recognition app
% Created 07-Feb-2021 15:50:44
% This script assumes these variables are defined:
% x - input data.
% t - target data.
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
% Create a Pattern Recognition Network
hiddenLayerSize = [5 4 3];
net = patternnet(hiddenLayerSize, trainFcn);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
% View the Network
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotconfusion(t,y)
%figure, plotroc(t,y)

Accepted Answer

the cyclist
the cyclist on 12 Apr 2021
Your question, especially when you ask about the 88x88 matrix that is output from pca(), indicates that you don't really understand the output. (The output is not the new variables.)
I have written a very extensive explanation of PCA, in response to this question. If you thoroughly understand that answer, you should be able to solve your problem.
the cyclist
the cyclist on 14 Apr 2021
@Ali Zulfikaroglu, responding to your email question here.
Unfortunately, I am not very knowledgeable about artificial neural networks, and can provide no advice on improving your accuracy.
I will say that just wanting your accuracy to be higher is very different from having a system that is able to be accurately predicted. If there is variation in the output that is not explained by your inputs (i.e. noise), then even the optimal model is limited in its accuracy.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!