In order to achieve this workflow, the generated function that is exported from the Regression Learner App using the option "Generate Function" should be customized.
To do so, a call to function 'compact' needs to be added after creating the 'regressionTree' object in the exported function, namely,
regressionTree = fitrtree(...
predictors, ...
response, ...
'MinLeafSize', 4, ...
'Surrogate', 'off');
regressionTree = compact(regressionTree);
For more information on how to construct a compact regression tree, please visit the following documentation page,
Then, the following lines in the exported function should be comment out,
because the RMSE cannot be computed anymore since the regression object no longer has training data. Lastly, the function signature of the exported function needs to be changed, such that it no longer returns variable 'validationRMSE', namely,
function trainedModel = trainRegressionModel(trainingData, responseData)
Then, the resulting regression object should have the same size as the one exported by the Regression Learner App when using option "Export Compact Model".
Best Answer