Translating linear SVM classification algorithm to C using MATLAB Coder

조회 수: 3 (최근 30일)
I've trained a linear SVM classifier using the Classification Learner app, and exported the model to a .mat file. I'm attempting to translate this algorithm to C using MATLAB Coder, but am getting an error.
I'm not sure if I'm approaching the problem correctly, but my current approach is to load the .mat file as I would do in MATLAB, and then call the classification prediction function using values that are passed in (this assumes that using load() would normally work in MATLAB Coder, of which I'm not sure). When running the "Check for issues" step in MATLAB coder, the following error is triggered:
Found unsupported class for variable using function 'load'. MATLAB class 'ClassificationSVM' found at 'classifier.trainedClassifier.ClassificationSVM' is unsupported.
Use the command 'whos -file classifierOptimal.mat' to view the variables in the MAT file.
It would appear that the MATLAB class used for classification is unsupported in MATLAB coder.
How do I translate this classification algorithm for use outside of MATLAB?

채택된 답변

Walter Roberson
Walter Roberson 2016년 4월 5일
  댓글 수: 2
Paul Van Wieren
Paul Van Wieren 2016년 4월 5일
Thanks for the tip. Do you have any suggestions for a workaround? It's starting to sound like I'll need to manually write a classifier that uses the properties of my trained model?
Walter Roberson
Walter Roberson 2016년 4월 5일
I have not looked at the structure of the output of the newer SVM classifiers.
Back when I was working on data classification, SVM returned a dividing vector that could be saved. After that, the process of classification was simply deciding which side of the vector that any given sample was on. That did not require the SVM routines, just the saved vector.
If you are trying to generate code that will perform SVM classification, then you are probably best off calling into libsvm. It appears that package might now live at https://github.com/cjlin1/libsvm

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Shyamal Patel
Shyamal Patel 2016년 11월 17일
Code generation for trained SVM and logistic regression models is now supported in the Statistics and Machine Learning Toolbox. Please refer to the following documentation page for more information: Code Generation Workflows for Machine Learning

Community Treasure Hunt

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

Start Hunting!

Translated by