現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)
