Why do I get "cannot load an object of class 'compactcl​assificati​onECOC'" after compiling a standalone application of a machine learning model?

I have a trained machine learning model saved as a MAT file that is loaded in my App Designer application.
When I compile the app into a standalone application with MATLAB Compiler, I get the following error when running it:
ERROR: cannot load an object of class 'compactclassificationECOC'

 Accepted Answer

During the compilation process, a dependency analysis is run to pick up files that the code relies on. In this case, the dependent functions are specified as a  value in the trained model struct loaded through a MAT file. This causes the analysis to miss the necessary files.
To work around this, we can add a "function pragma" to the function to make the dependency explicit:
% App designer method
function myAppCallback(app, event)
%#function classreg.learning.classif.CompactClassificationECOC
[ additional code ]
The "function pragma" was added based on the "ClassificationSVM" values in the trained model struct:
trainedModel =
struct with fields:
predictFcn: @(x)exportableModel.predictFcn(predictorExtractionFcn(x))
ClassificationSVM: [1×1 classreg.learning.classif.CompactClassificationECOC]
About: 'This struct is a trained model exported from Classification Learner R2017b.'
HowToPredict: 'To make predictions on a new predictor column matrix, X, use: ...
Multiple functions can be added to the pragma with spaces:
%#function classreg.learning.classif.CompactClassificationECOC classreg.learning.regr.RegressionModel
Additional information about the "function pragma" can be found in the following link (see example 3 in particular):
Some of the warnings will remain, but those are known and expected and will not affect the functionality of the application.

More Answers (0)

Products

Release

R2017b

Community Treasure Hunt

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

Start Hunting!