- 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?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
phdcomputer Eng
el 22 de Dic. de 2019
Editada: phdcomputer Eng
el 22 de Dic. de 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 comentarios
Image Analyst
el 22 de Dic. de 2019
Respuesta aceptada
dpb
el 22 de Dic. de 2019
Editada: dpb
el 22 de Dic. de 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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Get Started with Statistics and Machine Learning Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!