Main Content

predict

R2026b

Predict responses using regression XGBoost model

Since R2026a

    Description

    Yfit = predict(mdl,X) returns a vector of predicted responses for the predictor data in the table or matrix X, based on the pretrained XGBoost regression model mdl.

    example

    Yfit = predict(mdl,X,UseParallel=UseParallel) specifies whether to perform computations in parallel.

    Examples

    collapse all

    Import a pretrained XGBoost regression model trained using the carsmall data set to predict the fuel economy (MPG) of a car. The pretrained model is provided with this example and was trained in Python using Cylinders, Displacement, Horsepower, and Weight as predictors.

    load carsmall
    modelfile = "trainedRegressionXGBoostModel.json";
    Mdl = importModelFromXGBoost(modelfile)
    Mdl = 
      CompactRegressionXGBoost
                   ResponseName: 'Y'
              ResponseTransform: 'none'
                     NumTrained: 30
        ImportedModelParameters: [1×1 struct]
    
    
      Properties, Methods
    
    

    Predict the MPG for a car with 4 cylinders, 200 cubic inch engine displacement, 150 horsepower, and that weighs 3000 lbs.

    X0 = [4 200 150 3000];
    predict(Mdl,X0)
    ans = single
    
    24.0842
    

    The XGBoost model predicts the car's efficiency to be 24.08 mpg.

    Input Arguments

    collapse all

    Compact regression XGBoost model, specified as a CompactRegressionXGBoost model object created with importModelFromXGBoost.

    Predictor data used to predict responses, specified as a numeric matrix or a table.

    Each row of X corresponds to one observation, and each column corresponds to one variable. If there are missing values in a row, the software uses the learned branch direction from the pretrained model. The predictor data cannot include categorical predictors (logical, categorical, char, string, or cell).

    For a numeric matrix, the variables that make up the columns of X must have the same order as the predictor variables used to train mdl.

    For a table:

    • predict does not support multicolumn variables or cell arrays other than cell arrays of character vectors.

    • All predictor variables in X must have the same variable names and data types as those stored in mdl.PredictorNames. X can contain additional variables, such as response variables and observation weights, but predict ignores them.

    Option to perform computations in parallel using a parallel pool of workers, specified as one of these values:

    • "off" — Run in serial on the MATLAB® client.

    • "auto" — Use a parallel pool if one is open or if MATLAB can automatically create one. If a parallel pool is not available, run in serial on the MATLAB client.

    • "on" — Use a parallel pool if one is open or if MATLAB can automatically create one. If a parallel pool is not available, throw an error.

    If you do not have a parallel pool open and automatic pool creation is enabled, MATLAB opens a pool using the default cluster profile. To use a parallel pool to run computations in MATLAB, you must have Parallel Computing Toolbox™. For more information, see Run MATLAB Functions with Automatic Parallel Support (Parallel Computing Toolbox).

    Before R2026b: To run in parallel, set UseParallel to true.

    Example: UseParallel="auto"

    Data Types: char | string

    Output Arguments

    collapse all

    Predicted response values, returned as a numeric column vector with the same number of rows as X. Each row of Yfit gives the predicted response to the corresponding row of X, based on the regression XGBoost model mdl.

    Alternative Functionality

    Simulink Block

    To integrate the prediction of an XGBoost classification model into Simulink®, you can use the RegressionNeuralNetwork Predict block in the Statistics and Machine Learning Toolbox™ library or a MATLAB Function block with the predict function. For example, see Predict Class Labels Using MATLAB Function Block.

    When deciding which approach to use, consider the following:

    • If you use the Statistics and Machine Learning Toolbox library block, you can use the Fixed-Point Tool (Fixed-Point Designer) to convert a floating-point model to fixed point.

    • Support for variable-size arrays must be enabled for a MATLAB Function block with the predict function.

    • If you use a MATLAB Function block, you can use MATLAB functions for preprocessing or post-processing before or after predictions in the same MATLAB Function block.

    Extended Capabilities

    expand all

    Version History

    Introduced in R2026a

    expand all