Main Content

Import Trained Model into Classification Learner or Regression Learner

R2026b
Since R2026a

You can import a trained machine learning model into the Classification Learner app or the Regression Learner app using several different methods:

A trained model must meet certain requirements to be importable. For details, see Restrictions on Importing Models.

After you import a trained model, you can compare its performance with other models in the app using test metrics, and explain the imported model's behavior using model interpretability plots available in the app.

Start New Session from Trained MATLAB Model

If you have a trained MATLAB model in your workspace, you can import the model and its training data into a new app session. You cannot import a compact model.

  1. On the Apps tab, display the apps gallery. Under Machine Learning and Deep Learning, click the icon for the app you want to open.

  2. On the Learn tab of the app, in the File section, select New Session > From Trained Model.

  3. In the New Session from Trained Model dialog box, under Workspace Model Variable, select a trained model from the list of supported trained models. The dialog box displays details about the model's training data set in the workspace variable.

    New session from trained model

    You can select a validation scheme for new models that you create and train in the app session. Note that the validation scheme does not apply to imported models. The default validation scheme is 5-fold cross-validation, which protects against overfitting.

    Tip

    If you are importing a large data set, you might want to select holdout validation. For more information, see Select Validation Scheme in Classification Learner or Regression Learner.

  4. To accept the default validation scheme and continue, click Start Session. The imported model appears in the Models pane with the label Imported label.

  5. On the Summary tab, expand the Model Hyperparameters section to view a list of hyperparameters in the imported model. The hyperparameter names correspond to the input arguments of the MATLAB fit function used to train the model. The app retrieves the hyperparameter values from the ModelParameters property in the workspace model variable.

    Summary tab of imported trained model showing model hyperparameters

For information on how to train new models, see Train Classification Models in Classification Learner App and Train Regression Models in Regression Learner App.

Import Trained Model into Current Session

You can import any of the following models into the current session, provided that the model satisfies the requirements listed in Restrictions on Importing Models.

To import a trained model from the MATLAB workspace, complete the following steps.

  1. On the Learn tab, in the File section, select Import Model > Import Trained Model from Workspace.

  2. In the Import Trained Model from Workspace dialog box, under Workspace Model Variable, select a supported trained model from the list of workspace variables. To examine the details of a trained model in the workspace, select the workspace variable and view the information in the Model information section of the dialog box.

    Import trained model

  3. Modify the imported model name, if necessary, and click Import. The model appears in the Models pane with the imported model name and the label Imported label.

    Note

    When you import a trained model, its training data remains attached to the model but is not used in the app. The current app session's training data set remains unaffected. XGBoost models in the workspace do not contain training data.

  4. On the Summary tab, click Model Hyperparameters to view a list of model hyperparameters. The hyperparameter names correspond to the input arguments of the MATLAB fit function used to train the model. The app retrieves the hyperparameter values from the ModelParameters property in the workspace model variable. Model hyperparameter information is not available for imported compact models or XGBoost models.

    Summary tab of imported trained model showing model hyperparameters

Import Trained XGBoost Model from JSON File

Since R2026b

In the current app session, you can import a trained XGBoost model saved as a JSON file in Python with the extension ".json". For more information, see Save XGBoost Model in Python.

  1. On the Learn tab, in the File section, select Import Model > Import Trained XGBoost Model from JSON File.

  2. In the Import Trained XGBoost Model from JSON File dialog box, select or enter the name of the JSON file you want to import. The Model information section of the dialog box displays information about the XGBoost model. The predictors in the model must be compatible with those in the training data set of the current session (see Restrictions on Importing Models).

    Import trained XGBoost model

  3. Modify the imported model name, if necessary, and click Import. The model appears in the Models pane with the imported model name and the label Imported label. The model Summary tab lists additional information about the model. Model hyperparameter information is not available for imported XGBoost models.

Restrictions on Importing Models

The following restrictions apply to all imported models:

  • You cannot import a regression model into Classification Learner, or import a classifier model into Regression Learner.

  • When you import a trained model into the current session, each predictor in the model must have a corresponding predictor, with the same name, in the current session's training data set. If a model predictor is categorical (according to the model's CategoricalPredictors property), the corresponding predictor in the training data set must also be categorical. In Classification Learner, the response variable in the trained model must have the same data type and the same set of classes as the response variable in the current session.

    Tip

    If you start a new app session by importing data from a file or from a matrix variable in the workspace, the app might assign default names to the response variable and predictors. These default names might not match the names in a command-line trained model that you train on the same data set. To ensure matching predictor and response variable names, convert your data into a table variable before training models at the command line or importing the data into Classification Learner or Regression Learner.

  • The model must be trained on predictor and response variables that are numeric, categorical, string, or logical vectors, cell arrays of character vectors, or character arrays. A variable cannot contain all NaN values.

  • You cannot duplicate imported models or train them on the training or validation data sets in the app. The app does not display validation metrics or plots of validation results for an imported model, because the model was not trained using the same validation scheme as other models in the app session. You can assess the performance of an imported model by testing it on a test data set in Classification Learner or Regression Learner. For more information, see Test Trained Models in Classification Learner or Regression Learner.

  • You cannot export an imported model to Experiment Manager.

The following restrictions apply to XGBoost models:

The following restrictions apply to MATLAB models:

See Also

Topics