- attach colon.mat and
- include the entire error message (ALL the red text), including the line of code that threw that error
- indent your code (control-a, control-i in the MATLAB editor)
how to compute the average of several repeats of a program in matlab?
3 views (last 30 days)
Show older comments
I wrote this program to classify the dataset(colon) and compute the accuracy of the classifier, I wanted to repeat the classification 10 times and save the results in an array(Arforest)and then compute the average of these results(averf) but when I test size(Arforest) the size of the result is 1 so any array isn't shaped.
clc;
clear;
close all;
tic
load colon.mat
data=colon; [n,m]=size(data);
rows=(1:n);
test_count=floor((0.2)*n);
sum_ens=0;sum_result=0;
it=10;
for k=1:it
test_rows=randsample(rows,test_count);
train_rows=setdiff(rows,test_rows);
test=data(test_rows,:);
train=data(train_rows,:);
xtest=test(:,1:m-1);
ytest=test(:,m);
xtrain=train(:,1:m-1);
ytrain=train(:,m);
[rforest, DT , sk ] = classificationa(xtest,xtrain,ytrain);
[Arforest, ADT , Ask] = allaccuracydata(rforest, DT , sk , ytest);
end
averf=mean(Arforest);
avedt=mean(ADT);
avesk=mean(Ask);
Arforest is the result of Random Forest classifier,
when I use the counter (k) an error shows:
it=10;
for k=1:it
[rforest, DT , sk ] = classificationa(xtest,xtrain,ytrain);
[Arforest(k), ADT(k) , Ask(k)] = allaccuracydata(rforest(k), DT(k) , sk(k) , ytest);
end
averf=mean(Arforest);
avedt=mean(ADT);
avesk=mean(Ask);
the error is:
Error: File: myFSmethod20.m Line: 157 Column: 19
An array for multiple LHS assignment cannot contain expressions.
I'll be gratefull to have your opinions to obtain true result.Thanks
2 Comments
Image Analyst
on 22 Dec 2019
Accepted Answer
dpb
on 22 Dec 2019
Edited: dpb
on 22 Dec 2019
An array for multiple LHS assignment cannot contain expressions.
in
[Arforest(k), ADT(k) , Ask(k)] = allaccuracydata(rforest(k), DT(k) , sk(k) , ytest);
the arguments to allaccuracydata aren't arrays; they're the single-case results from the previous line. Just assign the results:
[Arforest(k) ADT(k) Ask(k)] = allaccuracydata(rforest,DT,sk,ytest);
each loop.
It would be better to preallocate the LHS arrays prior to beginning the loop.
2 Comments
More Answers (0)
See Also
Categories
Find more on Get Started with Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!