Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

代码生成

为 Statistics and Machine Learning Toolbox™ 函数生成 C/C++ 代码和 MEX 函数

MATLAB® Coder™ 可从支持代码生成的 Statistics and Machine Learning Toolbox 函数中生成可读且可移植的 C 代码和 C++ 代码。例如,您可以利用代码生成,将经过训练的支持向量机 (SVM) 分类模型部署到不能运行 MATLAB 的硬件设备上,在这些硬件设备上对新观测值进行分类。

您可以通过多种方式为这些函数生成 C/C++ 代码:

  • 对机器学习模型的对象函数使用 saveLearnerForCoderloadLearnerForCodercodegen (MATLAB Coder)

  • 对机器学习模型的 predictupdate 对象函数使用由 learnerCoderConfigurer 创建的代码生成器配置器。使用配置器配置代码生成选项,并在生成代码中更新模型参数。

  • 对于支持代码生成的其他函数,使用 codegen

您还可以生成定点 C/C++ 代码,用于预测一些机器学习模型。这种类型的代码生成需要 Fixed-Point Designer™。

要将机器学习模型的预测集成到 Simulink® 中,请使用 Statistics and Machine Learning Toolbox 库中的 MATLAB Function 模块或 Simulink 模块。

要了解代码生成,请参阅Introduction to Code Generation

有关支持代码生成的函数的列表,请参阅函数列表(C/C++ 代码生成)

函数

全部展开

saveLearnerForCoderSave model object in file for code generation (自 R2019b 起)
loadLearnerForCoderReconstruct model object from saved model for code generation (自 R2019b 起)
generateLearnerDataTypeFcnGenerate function that defines data types for fixed-point code generation (自 R2019b 起)

创建代码生成器配置器对象

learnerCoderConfigurerCreate coder configurer of machine learning model

使用代码生成器配置器对象

generateCodeGenerate C/C++ code using coder configurer
generateFilesGenerate MATLAB files for code generation using coder configurer
validatedUpdateInputsValidate and extract machine learning model parameters to update
updateUpdate model parameters for code generation

对象

全部展开

ClassificationTreeCoderConfigurerCoder configurer of binary decision tree model for multiclass classification (自 R2019b 起)
ClassificationSVMCoderConfigurerCoder configurer for support vector machine (SVM) for one-class and binary classification
ClassificationLinearCoderConfigurerCoder configurer for linear binary classification of high-dimensional data (自 R2019b 起)
ClassificationECOCCoderConfigurerCoder configurer for multiclass model using binary learners
RegressionTreeCoderConfigurerCoder configurer of binary decision tree model for regression (自 R2019b 起)
RegressionSVMCoderConfigurerCoder configurer for support vector machine (SVM) regression model
RegressionLinearCoderConfigurerCoder configurer for linear regression model with high-dimensional data (自 R2019b 起)

模块

全部展开

ClassificationECOC PredictClassify observations using error-correcting output codes (ECOC) classification model (自 R2023a 起)
ClassificationEnsemble PredictClassify observations using ensemble of decision trees (自 R2021a 起)
ClassificationKNN PredictClassify observations using nearest neighbor classification model (自 R2022b 起)
ClassificationLinear PredictClassify observations using linear classification model (自 R2023a 起)
ClassificationNaiveBayes PredictClassify observations using naive Bayes model (自 R2023b 起)
ClassificationNeuralNetwork PredictClassify observations using neural network classification model (自 R2021b 起)
ClassificationSVM PredictClassify observations using support vector machine (SVM) classifier for one-class and binary classification (自 R2020b 起)
ClassificationTree PredictClassify observations using decision tree classifier (自 R2021a 起)
RegressionEnsemble PredictPredict responses using ensemble of decision trees for regression (自 R2021a 起)
RegressionGP PredictPredict responses using Gaussian process (GP) regression model (自 R2022a 起)
RegressionLinear Predict使用线性回归模型预测响应 (自 R2023a 起)
RegressionNeuralNetwork PredictPredict responses using neural network regression model (自 R2021b 起)
RegressionSVM Predict使用支持向量机 (SVM) 回归模型预测响应 (自 R2020b 起)
RegressionTree PredictPredict responses using regression tree model (自 R2021a 起)
IncrementalClassificationLinear PredictClassify observations using incremental linear classification model (自 R2023b 起)
IncrementalClassificationLinear FitFit incremental linear binary classification model (自 R2023b 起)
IncrementalRegressionLinear PredictPredict responses using incremental linear regression model (自 R2023b 起)
IncrementalRegressionLinear FitFit incremental linear regression model (自 R2023b 起)
Update MetricsUpdate performance metrics in incremental learning model given new data (自 R2023b 起)
KNN SearchFind k-nearest neighbors using searcher object (自 R2023b 起)

主题

代码生成工作流

分类和回归预测模块

增量学习模块

聚类分析模块

代码生成应用程序