Error using zeros Size inputs must be scalar.
이전 댓글 표시
fileID = 'kddcup.testdata.unlabeled_10_percent.txt';
input= xlsread('KDDTrain.xls');
target = fopen(fileID);
%target= load('kddcup.testdata.unlabeled_10_percent.txt');
testData= xlsread('KDDTest.xls');
%% Formating of dataset
% p=T(:,0.70)';
% t=T(:,0.30)';
ivp=input';
ivt=target';
testinputs=testData';
[trainx, testy]=mapminmax(ivp,ivt);
%% DataSet dimensions
numberOfClasses = max(input);
numberOfRecords = size(input, 1);
numberOfFeatures = size(input, 2) - 1;
% dataSet = correct
%% Max - Win target Preparation
target = zeros(numberOfClasses, numberOfRecords);
Ind = sub2ind(size(target), input', 1:numberOfRecords);
target(Ind) = 1;
target = target*2-1;
%% Multilayer Perceptron Network Initialization
mlp = feedforwardnet([5 7]);
mlp.layers{1}.transferFcn = 'tansig';
mlp.layer{2}.transferFcn = 'tansig';
mlp.trainFcn = 'trainlm'; % Training Function
mlp.performFcn = 'mse'; % performance Function
%% Training parameters
mlp.train.Param.min_grad = 10^-7;
mlp.train.Param.epochs = 1000;
mlp.train.Param.time = inf;
mlp.train.Param.goal = 0;
mlp.train.Param.showWindow = true;
%% Training the Neural Network
mlp = train(mlp, input(:,numberOfFeatures)', target);
%% Testing the Neural Network on the training dataset
[~, outputs] = max(mlp(input(:, 1:numberOfFeatures)'));
%% Calculate the Accuracy
accuracy = lenght(find(output == input'))/numberOfRecords
Please,
I need help with the code line below.
And a walk through the code to see if the code will pull through else point to me where my code is wrong and possible alterations/ changes.
I have been battling with this code for a long time now but couldn't seem to have pulled through.
this line seem to pull the above error in question:
target = zeros(numberOfClasses, numberOfRecords);
댓글 수: 9
dpb
2019년 9월 21일
target = zeros(numberOfClasses,numberOfRecords, 'like',h);
At that point, h is undefined in the above code.
Williams Ofor
2019년 9월 21일
Guillaume
2019년 9월 21일
This is the code I am using
target = zeros(numberOfClasses, numberOfRecords);
numberOfClasses is a 1x41 double [apparently full of 0s]
Well, don't you see there's a problem right there? What are you hoping that
zero(vector_full_of_0s, scalar)
is going to do?
Williams Ofor
2019년 9월 22일
Walter Roberson
2019년 9월 22일
numberOfClasses = max(input);
We as outside observers have no reason to expect that input contains only non-negative integers. But as the first step I suggest
numberOfClasses = max(input(:));
to get the overall maximum instead of the column-by-column maximum.
Even then I would suggest that it would be more likely that one column of the input contains the information about class.
target = fopen(fileID);
Did you notice that you are not reading from the file? You are only opening it and using the file identifier (which would most often be 3) as the target number.
Williams Ofor
2019년 9월 23일
Guillaume
2019년 9월 23일
You're stll not reading anything from your text file, so it's not clear what it's doing there.
As I wrote in my answer for that sub2ind call to work all inputs must be the same size/shape (you appear to have fixed that) and must be valid subscripts: strictly positive integer less than or equal to the size of the corresponding dimension. The less than or equal is guaranteed with your code, so clearly it's the strictly positive that your code is violating.
Williams Ofor
2019년 9월 23일
편집: Williams Ofor
2019년 9월 24일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Deep Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!