이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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
조회 수: 9 (최근 30일)
이전 댓글 표시
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
Doli Hazarika
2022년 3월 2일
While running the following line of code:
Mdl = fitcensemble(X,Y,'Method','Subspace','NPredToSample',5, ...
'Learners',learner,'NumLearningCycles',13);
it is showing an error stating:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
syntax error. To construct matrices, use brackets instead of parentheses.
Walter Roberson
2022년 3월 2일
There is a possibility that it is complaining about a previous line not being complete.
Doli Hazarika
2022년 3월 2일
load ionosphere
rng('default') % For reproducibility
learner = templateKNN('NumNeighbors',2);
Mdl = fitcensemble(X,Y,'Method','Subspace','NPredToSample',5, ...
'Learners',learner,'NumLearningCycles',13);
this are the lines of code that I am running. It shows the following error:
File: fitcensemble.m Line: 1 Column: 33
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other
syntax error. To construct matrices, use brackets instead of parentheses.
Error in Classification (line 4)
Mdl = fitcensemble(X,Y,'Method','Subspace','NPredToSample',5, ...
Walter Roberson
2022년 3월 2일
편집: Walter Roberson
2022년 3월 2일
Please show
which -all fitcensemble
dbtype fitcensemble 1:5
Doli Hazarika
2022년 3월 2일
>> which -all fitcensemble
E:\Doli\MATLAB codes\fitcensemble.m
C:\Program Files\MATLAB\R2021a\toolbox\stats\classreg\fitcensemble.m % Shadowed
>> dbtype fitcensemble 1:5
1 function Mdl = fitcensemble(X,Y,'Bag')
2 %UNTITLED Summary of this function goes here
3 % Detailed explanation goes here
4 rng('default')
5 t = templateTree('Reproducible', true);
Walter Roberson
2022년 3월 2일
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
2022년 3월 4일
I tried but it is still showing the following error. I am unable to understand from the error
Maximum recursion limit of 500 reached.
Error in fitcensemble (line 7)
Mdl = fitcensemble(X,Y,'Bag',varargin{:});
Caused by:
Maximum recursion limit of 500 reached.
Walter Roberson
2022년 3월 4일
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
1 load ionosphere
2 rng('default') % For reproducibility
3 learner = templateKNN('NumNeighbors',2);
4 Mdl = fitcensemble(X,Y,'Method','Subspace','NPredToSample',5, ...
5 'Learners',learner,'NumLearningCycles',13);
%now run the code
my_fitcensemble
%check the results
whos
Name Size Bytes Class Attributes
Description 5x79 790 char
Mdl 1x1 613095 classreg.learning.classif.ClassificationEnsemble
PROGRAM 1x1 562 string
X 351x34 95472 double
Y 351x1 37206 cell
ans 1x1 8 double
fid 1x1 8 double
learner 1x1 2078 classreg.learning.FitTemplate
Doli Hazarika
2022년 3월 7일
Yes it worked this way. But instead of creating a function and calling it directly why are we doing it this way?
Walter Roberson
2022년 3월 7일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Programming Utilities에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
