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
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 2 Mar 2022
What problem are you observing?
Doli Hazarika
le 2 Mar 2022
Walter Roberson
le 2 Mar 2022
There is a possibility that it is complaining about a previous line not being complete.
Doli Hazarika
le 2 Mar 2022
Walter Roberson
le 2 Mar 2022
Modifié(e) : Walter Roberson
le 2 Mar 2022
Please show
which -all fitcensemble
dbtype fitcensemble 1:5
Doli Hazarika
le 2 Mar 2022
Walter Roberson
le 2 Mar 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
le 4 Mar 2022
Walter Roberson
le 4 Mar 2022
Notice that you need to rename your function and the file it is in.
Doli Hazarika
le 4 Mar 2022
Doli Hazarika
le 4 Mar 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
le 7 Mar 2022
Walter Roberson
le 7 Mar 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
le 8 Mar 2022
Réponses (0)
Catégories
En savoir plus sur Programming Utilities dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!