Contenuto principale

predict

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

    Flag to run in parallel, specified as a numeric or logical 1 (true) or 0 (false). If you specify UseParallel=true, the predict function executes for-loop iterations by using parfor. The loop runs in parallel when you have Parallel Computing Toolbox™.

    Example: UseParallel=true

    Data Types: logical

    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.

    Extended Capabilities

    expand all

    Version History

    Introduced in R2026a