Loading Classification Model in Simulink created using MATLAB Classification Learner App

9 vues (au cours des 30 derniers jours)
I have trained a classification model using Matlab's Classification Learner App. I have exported it to the workspace and also saved it as a .mat file.
I need to embed it in a Simulink model to make predictions at every time step during simulation. I've tried multiple things like:
  1. Using a From File block to load the classification model from the .mat file and then using mdl.predictFcn(myInputData) to make a prediction on new data.
  2. Pre-loading the model in workspace and then accessing it using a Matlab Function
However, both of these methods do not work. The first method gives me an error stating that the .mat file can only have timeseries data (which it doesn't as it is a classification model) and the second method is not able to identify the pre-loaded model in the workspace.
Can someone guide me in solving this issue. Thanks

Réponses (1)

Drew
Drew le 3 Nov 2023
MathWorks provides Simulink blocks for machine learning model prediction. So, you can use the native Simulink block designed for model prediction with your machine learning model. Check the "Blocks" section of the doc page https://www.mathworks.com/help/stats/code-generation.html
For example, from that doc page, here are Simulink blocks currently available for prediction with different types of ML Classifiers:
ClassificationECOC Predict Classify observations using error-correcting output codes (ECOC) classification model (Since R2023a)
ClassificationEnsemble Predict Classify observations using ensemble of decision trees (Since R2021a)
ClassificationKNN Predict Classify observations using nearest neighbor classification model (Since R2022b)
ClassificationLinear Predict Classify observations using linear classification model (Since R2023a)
ClassificationNaiveBayes Predict Classify observations using naive Bayes model (Since R2023b)
ClassificationNeuralNetwork Predict Classify observations using neural network classification model (Since R2021b)
ClassificationSVM Predict Classify observations using support vector machine (SVM) classifier for one-class and binary classification (Since R2020b)
ClassificationTree Predict Classify observations using decision tree classifier (Since R2021a)
if this answer helps you, please remember to accept the answer.

Community Treasure Hunt

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

Start Hunting!

Translated by