Main Content

La traducción de esta página está obsoleta. Haga clic aquí para ver la última versión en inglés.

Generación de código

Genere código C/C++ y funciones MEX para las funciones de Statistics and Machine Learning Toolbox™

MATLAB® Coder™ genera código C y C++ portátil y legible a partir de las funciones de Statistics and Machine Learning Toolbox compatibles con la generación de código. Por ejemplo, puede clasificar nuevas observaciones en dispositivos de hardware que no pueden ejecutar MATLAB mediante la implementación de un modelo de clasificación de máquina de vectores de apoyo (SVM, por sus siglas en inglés) entrenado en el dispositivo que utiliza la generación de código.

Puede generar código C/C++ para estas funciones de varias maneras:

  • Utilice saveLearnerForCoder, loadLearnerForCoder y codegen (MATLAB Coder) para una función de objeto de un modelo de machine learning.

  • Utilice un configurador de codificadores creado por learnerCoderConfigurer para las funciones de objeto predict y update de un modelo de machine learning. Configure las opciones de generación de código mediante el configurador y actualice los parámetros del modelo en el código generado.

  • Utilice codegen para otras funciones compatibles con la generación de código.

También puede generar código C/C++ de punto fijo para la predicción de algunos modelos de machine learning. Este tipo de generación de código requiere Fixed-Point Designer™.

Para integrar la predicción de un modelo de machine learning en Simulink®, utilice un bloque de funciones de MATLAB o los bloques de Simulink de la biblioteca de Statistics and Machine Learning Toolbox.

Para obtener información sobre la generación de código, consulte Introduction to Code Generation.

Para obtener una lista de las funciones compatibles con la generación de código, consulte Lista de funciones (generación de código C/C++).

Funciones

expandir todo

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

Crear un objeto de configurador de codificadores

learnerCoderConfigurerCreate coder configurer of machine learning model

Trabajar con un objeto de configurador de codificadores

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

Objetos

expandir todo

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

Bloques

expandir todo

ClassificationSVM PredictClassify observations using support vector machine (SVM) classifier for one-class and binary classification
ClassificationTree PredictClassify observations using decision tree classifier
ClassificationEnsemble PredictClassify observations using ensemble of decision trees
RegressionSVM PredictPredecir las respuestas mediante un modelo de regresión de máquina de vectores de apoyo (SVM)
RegressionTree PredictPredict responses using regression tree model
RegressionEnsemble PredictPredict responses using ensemble of decision trees for regression

Temas

Flujos de trabajo de generación de código

Introduction to Code Generation

Learn how to generate C/C++ code for Statistics and Machine Learning Toolbox functions.

General Code Generation Workflow

Generate code for Statistics and Machine Learning Toolbox functions that do not use machine learning model objects.

Code Generation for Prediction of Machine Learning Model at Command Line

Generate code for the prediction of a classification or regression model at the command line.

Code Generation for Incremental Learning

Generate code that implements incremental learning for binary linear classification at the command line.

Code Generation for Prediction of Machine Learning Model Using MATLAB Coder App

Generate code for the prediction of a classification or regression model by using the MATLAB Coder app.

Code Generation for Prediction and Update Using Coder Configurer

Generate code for the prediction of a model using a coder configurer, and update model parameters in the generated code.

Specify Variable-Size Arguments for Code Generation

Generate code that accepts input arguments whose size might change at run time.

Generate Code to Classify Data in Table

Generate code for classifying data in a table containing numeric and categorical variables.

Create Dummy Variables for Categorical Predictors and Generate C/C++ Code

Convert categorical predictors to numeric dummy variables before fitting an SVM classifier and generating code.

Fixed-Point Code Generation for Prediction of SVM

Generate fixed-point code for the prediction of an SVM classification or regression model.

Code Generation and Classification Learner App

Train a classification model using the Classification Learner app, and generate C/C++ code for prediction.

Code Generation for Nearest Neighbor Searcher

Generate code for finding nearest neighbors using a nearest neighbor searcher model.

Code Generation for Probability Distribution Objects

Generate code that fits a probability distribution object to sample data and evaluates the fitted distribution object.

Code Generation for Logistic Regression Model Trained in Classification Learner

This example shows how to train a logistic regression model using Classification Learner, and then generate C code that predicts labels using the exported classification model.

Bloques de predicción de clasificación y regresión

Predict Class Labels Using ClassificationSVM Predict Block

This example shows how to use the ClassificationSVM Predict block for label prediction in Simulink®.

Predict Class Labels Using ClassificationTree Predict Block

Train a classification decision tree model using the Classification Learner app, and then use the ClassificationTree Predict block for label prediction.

Predict Class Labels Using ClassificationEnsemble Predict Block

Train a classification ensemble model with optimal hyperparameters, and then use the ClassificationEnsemble Predict block for label prediction.

Predict Responses Using RegressionSVM Predict Block

Train a support vector machine (SVM) regression model using the Regression Learner app, and then use the RegressionSVM Predict block for response prediction.

Predict Responses Using RegressionTree Predict Block

This example shows how to use the RegressionTree Predict block for response prediction in Simulink®.

Predict Responses Using RegressionEnsemble Predict Block

Train a regression ensemble model with optimal hyperparameters, and then use the RegressionEnsemble Predict block for response prediction.

Aplicaciones de generación de código

Predict Class Labels Using MATLAB Function Block

Generate code from a Simulink model that classifies data using an SVM model.

System Objects for Classification and Code Generation

Generate code from a System object™ for making predictions using a trained classification model, and use the System object in a Simulink model.

Predict Class Labels Using Stateflow

Generate code from a Stateflow® model that classifies data using a discriminant analysis classifier.

Human Activity Recognition Simulink Model for Fixed-Point Deployment

Generate code from a classification Simulink model prepared for fixed-point deployment.

Ejemplos destacados