主要内容

Import Trained Model from Workspace into Classification Learner or Regression Learner

Since R2026a

You can import a trained model and its training data from a workspace variable into the Classification Learner or Regression Learner app at the start of a new session. You can also import a trained model from the workspace during the current session if the model was trained on data that is compatible with the training data set in the current session. After you import a trained model, you can compare its performance with other models in the app using test metrics, or explain the imported model's behavior using model interpretability plots available in the app.

For a list of restrictions on imported models, see Restrictions on Imported Models.

Start New Session from Trained Model

If you have a trained model in your MATLAB® 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

To import a trained model into the current session, first make sure the model satisfies the following requirements:

  • The model must be trained in Classification Learner or Regression Learner, or at the MATLAB command line using a supported function. For a list of supported functions, see Restrictions on Imported Models.

  • 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.

  • The response variable in the trained model must have the same name and data type as the response variable in the current session. In Classification Learner, the response variable in the trained model must also have the same set of classes as the current session's response variable.

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.

  1. On the Learn tab, in the File section, click Import Model.

  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.

  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.

    Summary tab of imported trained model showing model hyperparameters

Restrictions on Imported Models

The restrictions below apply to imported models:

See Also

Topics