Unable to run the code given in the link: https://in.mathworks.com/help/stats/code-generation-for-prediction-of-machine-learning-model-using-matlab-coder-app.html
Mostrar comentarios más antiguos
Hi,
I have been trying to run the code given the following link: https://in.mathworks.com/help/stats/code-generation-for-prediction-of-machine-learning-model-using-matlab-coder-app.html. Currently I am using Matlab2021a version. Do I need to install 2021b to run this code or am I missing something else?
15 comentarios
Walter Roberson
el 2 de Mzo. de 2022
What problem are you observing?
Doli Hazarika
el 2 de Mzo. de 2022
Walter Roberson
el 2 de Mzo. de 2022
There is a possibility that it is complaining about a previous line not being complete.
Doli Hazarika
el 2 de Mzo. de 2022
Walter Roberson
el 2 de Mzo. de 2022
Editada: Walter Roberson
el 2 de Mzo. de 2022
Please show
which -all fitcensemble
dbtype fitcensemble 1:5
Doli Hazarika
el 2 de Mzo. de 2022
Walter Roberson
el 2 de Mzo. de 2022
Your E:\Doli\MATLAB codes\fitcensemble.m is interfering with calling the Mathworks fitcensemble function.
function Mdl = fitcensemble(X,Y,'Bag')
That is not valid syntax in defining a function. If you want to force Bag as the third parameter then you would want to do something like
function Mdl = my_fitcensemble(X,Y,varargin)
Mdl = fitcensemble(X, Y, 'Bag', varargin{:});
Doli Hazarika
el 4 de Mzo. de 2022
Walter Roberson
el 4 de Mzo. de 2022
Notice that you need to rename your function and the file it is in.
Doli Hazarika
el 4 de Mzo. de 2022
Doli Hazarika
el 4 de Mzo. de 2022
It does work.
%illustration that the code DOES work when saved to a file name that does
%not conflict
%first write the code into a .m file
PROGRAM = "load ionosphere\nrng('default') %% For reproducibility\nlearner = templateKNN('NumNeighbors',2);\nMdl = fitcensemble(X,Y,'Method','Subspace','NPredToSample',5, ...\n 'Learners',learner,'NumLearningCycles',13);";
fid = fopen('my_fitcensemble.m', 'w');
fprintf(fid, PROGRAM);
fclose(fid);
%now verify that the code looks like we expect
dbtype my_fitcensemble
%now run the code
my_fitcensemble
%check the results
whos
Doli Hazarika
el 7 de Mzo. de 2022
Walter Roberson
el 7 de Mzo. de 2022
I did it that way to prove that if you had a file with that content that it would work. All you need is the my_fitensemble file, not the code that creates it.
Doli Hazarika
el 8 de Mzo. de 2022
Respuestas (0)
Categorías
Más información sobre Programming Utilities en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!