Main Content

CompactRegressionXGBoost

Compact regression XGBoost model

Since R2026a

    Description

    Pretrained XGBoost model for regression. Use the compact regression XGBoost model for making predictions (regressions) of new data.

    Creation

    Create a CompactRegressionXGBoost object by importing a pretrained regression XGBoost model using importModelFromXGBoost.

    Properties

    expand all

    This property is read-only.

    Expanded predictor names, returned as a cell array of character vectors.

    For XGBoost models, ExpandedPredictorNames is the same as PredictorNames.

    Data Types: cell

    This property is read-only.

    Parameters of imported model, returned as a structure with 5 fields. This table lists the ImportedModelParameters fields and their values.

    Field NameValue
    BaseScoreInitial prediction score of all samples
    ObjectiveLearning objective
    BoosterType of weak learner used in gradient boosting. Only 'Tree' is supported.
    NumBoostingRoundsNumber of boosting rounds where each round involves fitting a new decision tree to the residuals
    HasParallelTrees1 if imported model has parallel trees, 0 otherwise

    This property is read-only.

    Number of trained weak learners in the ensemble, returned as a positive integer.

    Data Types: double

    This property is read-only.

    Predictor names, specified as a cell array of character vectors. The order of the entries in PredictorNames is the same as in the training data.

    Data Types: cell

    This property is read-only.

    Name of the response variable, returned as 'Y'.

    Data Types: char

    This property is read-only.

    Function for transforming raw response values. The default is "none", which means @(y)y, or no transformation.

    Data Types: char | string

    This property is read-only.

    Trained weak learners, returned as a cell array. The entries of the cell array contain the corresponding compact models as CompactRegressionTree objects.

    Data Types: cell

    This property is read-only.

    Trained weak learner weights, returned as a numeric vector. TrainedWeights has NumTrained elements, where NumTrained is the number of weak learners in the ensemble. The ensemble computes the predicted response by aggregating weighted predictions from its learners. For XGBoost models, the TrainedWeights are a vector of ones, signifying each learner has equal weight.

    Data Types: double

    Object Functions

    gatherGather properties of Statistics and Machine Learning Toolbox object from GPU
    limeLocal interpretable model-agnostic explanations (LIME)
    lossRegression error for XGBoost model
    partialDependenceCompute partial dependence
    plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
    predictPredict responses using regression XGBoost model
    predictorImportanceEstimates of predictor importance for XGBoost model
    shapleyShapley values

    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.

    The model was trained in Python using Cylinders, Displacement, Horsepower, and Weight as predictors. Then, it was saved as a json file using model.save_model('trainedRegressionXGBoostModel.json').

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

    The model is imported as a CompactRegressionXGBoost model object.

    Use the dot notation to view the imported model parameters.

    Mdl.ImportedModelParameters
    ans = struct with fields:
                BaseScore: 23.7181
                Objective: 'reg:squarederror'
                  Booster: 'Tree'
        NumBoostingRounds: 30
         HasParallelTrees: 1
    
    

    The parameters indicate it is a regression model trained using the 'Tree' booster and the 'reg:squarederror' objective.

    View one of the internal trees in the Mdl.Trained cell vector.

    view(Mdl.Trained{5})
    Decision tree for regression
     1  if x4<3086 then node 2 elseif x4>=3086 then node 3 else 3086
     2  if x3<90 then node 4 elseif x3>=90 then node 5 else 90
     3  if x3<108 then node 6 elseif x3>=108 then node 7 else 108
     4  if x4<2164 then node 8 elseif x4>=2164 then node 9 else 2164
     5  if x4<2774 then node 10 elseif x4>=2774 then node 11 else 2774
     6  if x3<105 then node 12 elseif x3>=105 then node 13 else 105
     7  fit = -0.268848
     8  if x4<1965 then node 14 elseif x4>=1965 then node 15 else 1965
     9  if x3<63 then node 16 elseif x3>=63 then node 17 else 63
    10  if x4<2575 then node 18 elseif x4>=2575 then node 19 else 2575
    11  if x4<2945 then node 20 elseif x4>=2945 then node 21 else 2945
    12  fit = -0.10735
    13  fit = -0.0197783
    14  fit = 0.0720372
    15  if x3<75 then node 22 elseif x3>=75 then node 23 else 75
    16  fit = 0.00183032
    17  fit = 0.144885
    18  if x3<92 then node 24 elseif x3>=92 then node 25 else 92
    19  fit = 0.0565872
    20  if x1<6 then node 26 elseif x1>=6 then node 27 else 6
    21  if x3<110 then node 28 elseif x3>=110 then node 29 else 110
    22  fit = 0.321683
    23  fit = 0.145527
    24  fit = 0.00116212
    25  fit = 0.0286452
    26  fit = 0.00162725
    27  fit = -0.0621072
    28  fit = -0.0205615
    29  fit = 0.0227947
    

    Tips

    For CompactRegressionXGBoost, the Trained property of Mdl stores a Mdl.NumTrained-by-1 cell vector of compact regression tree models. For a textual or graphical display of tree t in the cell vector, enter view(Mdl.Trained{t})

    Extended Capabilities

    expand all

    Version History

    Introduced in R2026a