- 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 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
phdcomputer Eng
le 22 Déc 2019
Modifié(e) : phdcomputer Eng
le 22 Déc 2019
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 commentaires
Image Analyst
le 22 Déc 2019
Réponse acceptée
dpb
le 22 Déc 2019
Modifié(e) : dpb
le 22 Déc 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Get Started with Statistics and Machine Learning Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!