regression model in simulink function block

5 次查看(过去 30 天)
Hi everyone. I need your help please . now for more than two weeks I cannot resolve the issue I have. I have trained a model for regression in regression learner and I have exported the trained model to my workspace and saved it as required and I have created a function to predict as mentioned in matlab website but when I use it in the simulink function block It doesnt work I have tried all possible ways mentioned in matlab website. please help. thanks
  2 个评论
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023-10-30
Some clarifcations are needed.
Q1: Can you share your model?
Q2: what simulink fcn were you trying to use?
Q3: what execise are you referring in MathWorks website or help documentation?
Djamel Guessoum
Djamel Guessoum 2023-10-31
this is the function i have inserted in the function block:
function ypred = mypredict_boosted_trees(tb)
%#function fitrtree
load('boosted_trees_model.mat');
ypred = trainedModel_boosted_trees.predictFcn(tb);
end
the errors received are:
The output of a call to 'load' is not assigned to a variable. Assign its output to a variable without subscripting.
Function 'MATLAB Function2' (#138.65.96), line 3, column 1:
"load('boosted_trees_model.mat')"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'trainedModel_boosted_trees.predictFcn'.
Function 'MATLAB Function2' (#138.106.147), line 4, column 9:
"trainedModel_boosted_trees.predictFcn(tb)"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of 'Voltage_maximum_function/MATLAB Function2'.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'Voltage_maximum_function/MATLAB Function2' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'Voltage_maximum_function/MATLAB Function2' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:Simulink | Category:Model error
Error in port widths or dimensions. Invalid dimension has been specified for input 'tb'.
Component:Simulink | Category:Model error

请先登录,再进行评论。

回答(1 个)

Drew
Drew 2023-11-3
MathWorks provides Simulink blocks for machine learning model prediction. So, rather than using a generic MATLAB function block for the model prediction, you can use the native Simulink block designed for model prediction for your machine learning model. Check the "Blocks" section of the doc page https://www.mathworks.com/help/stats/code-generation.html.
Given that your model is named "boosted_trees_model.mat", the matching Simulink block is probably the "RegressionEnsemble Predict" block:
If this answer helps you, please remember to accept the answer.
  1 个评论
Djamel Guessoum
Djamel Guessoum 2023-11-12
first of all thanks for your response and time given. I have tried to use the proper simulink block which is the regressionensemble block where i have updated with the saved model but it did not recognize it when i click refresh . still not working. ...thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Regression Tree Ensembles 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by