How to Apply PCA Corrrect way
1 次查看(过去 30 天)
显示 更早的评论
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.
veri=xlsread('data322.xlsx');
input=veri(:,1:88);
target=veri(:,89:91);
x=input';
t=target';
% 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
view(net)
% 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)
0 个评论
采纳的回答
the cyclist
2021-4-12
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.
6 个评论
the cyclist
2021-4-14
You do not need the de-meaning step. MATLAB internally de-means inside of PCA.
I'm surprised it has any impact on the accuracy of your NN, though.
the cyclist
2021-4-14
@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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!