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.
We know that numberOfRecords will be an integer (since it's the number of rows in the file), but there's absolutely no guarantee that numberOfClasses, the max of the data, is integer.
So, have you looked at the value of numberOfClasses? what is it?
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 で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!