To deploy the model, you would have to save the model from Classification Learners App. Please follow the steps below:
1. Once you have trained the model in the app, save that model using "Export Model" function from the app. This should generate a struct variable for the model in MATLAB workspace. Let it be "trainedModel"
2. Save the "trainedModel" struct into a "MAT" file. Lets say, "model.mat"
3. Write a "M" file to be deployed as a standalone application which should perform the following steps:
- Load "model.mat"
- Convert the input data from excel into "table" as model requires table datatype to execute.
- Extract "ClassificationTree" from the model.
- Perform a call to "predict" function passing "ClassificationTree" and the data from excel as Input parameters.
- The call to predict function would return a prediction based on input data and the trained model. Return this value.
- You cannot use "predictFcn" which is inside the "trainedModel" in a deployed target.
- Since there are more than one predict function in all the MATLAB toolboxes, you would have to use "function pragma" to let the dependency analyzer know which "predict" function to use. In this case we have to use "predict" function from "Classification Tree" method.
- The input data requirements may differ based on the model being used. In this case, the model requires data to be in form of table.
Even after including the ClassificationTree, the following warning message was received:
“Warning: Could not find appropriate function on path loading function handle <C:\Program Files\MATLAB\R2017a\toolbox\stats\mlearnapp\+mlearnapp\+internal\+model\DatasetSpecification.m>@(x)exportableModel.predictFcn(predictorExtractionFcn(x))>”
The error message is not clear enough to include the DataSetSpecification function. An enhancement request is raised for the same.
function yfit = runModelFromMATLAB(ValidationData)
ModTableData = ValidationData;
ModTableData = cell2table(ModTableData, 'VariableNames',...
ModelClassTree = trainedModel.ClassificationTree;
yfit = predict(ModelClassTree, ModTableData);
You can refer the following documentation.
・Deploy Predictions Using MATLAB Compiler