Main Content

CompactRegressionGAM

Compact generalized additive model (GAM) for regression

    Description

    CompactRegressionGAM is a compact version of a RegressionGAM model object (GAM for regression). The compact model does not include the data used for training the model. Therefore, you cannot perform some tasks, such as cross-validation, using the compact model. Use a compact model for tasks such as predicting the responses of new data.

    Creation

    Create a CompactRegressionGAM object from a full RegressionGAM model object by using compact.

    Properties

    expand all

    GAM Properties

    This property is read-only.

    Interaction term indices, specified as a t-by-2 matrix of positive integers, where t is the number of interaction terms in the model. Each row of the matrix represents one interaction term and contains the column indexes of the predictor data X for the interaction term. If the model does not include an interaction term, then this property is empty ([]).

    The software adds interaction terms to the model in the order of importance based on the p-values. Use this property to check the order of the interaction terms added to the model.

    Data Types: double

    This property is read-only.

    Intercept (constant) term of the model, which is the sum of the intercept terms in the predictor trees and interaction trees, specified as a numeric scalar.

    Data Types: single | double

    Flag indicating whether a model for the standard deviation of the response variable is fit, specified as false or true. Specify the 'FitStandardDeviation' name-value argument of fitrgam as true to fit the model for the standard deviation.

    If IsStandardDeviationFit is true, then you can evaluate the standard deviation at a new observation by using predict. This function also returns the prediction intervals of the response variable, evaluated at given observations.

    Data Types: logical

    Other Regression Properties

    This property is read-only.

    Categorical predictor indices, specified as a vector of positive integers. CategoricalPredictors contains index values indicating that the corresponding predictors are categorical. The index values are between 1 and p, where p is the number of predictors used to train the model. If none of the predictors are categorical, then this property is empty ([]).

    Data Types: double

    This property is read-only.

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

    ExpandedPredictorNames is the same as PredictorNames for a generalized additive model.

    Data Types: cell

    This property is read-only.

    Predictor variable names, specified as a cell array of character vectors. The order of the elements of PredictorNames corresponds to the order in which the predictor names appear in the training data.

    Data Types: cell

    This property is read-only.

    Response variable name, specified as a character vector.

    Data Types: char

    Response transformation function, specified as 'none' or a function handle. ResponseTransform describes how the software transforms raw response values.

    For a MATLAB® function or a function that you define, enter its function handle. For example, you can enter Mdl.ResponseTransform = @function, where function accepts a numeric vector of the original responses and returns a numeric vector of the same size containing the transformed responses.

    Data Types: char | function_handle

    Object Functions

    expand all

    limeLocal interpretable model-agnostic explanations (LIME)
    partialDependenceCompute partial dependence
    plotLocalEffectsPlot local effects of terms in generalized additive model (GAM)
    plotPartialDependenceCreate partial dependence plot (PDP) and individual conditional expectation (ICE) plots
    shapleyShapley values

    expand all

    predictPredict responses using generalized additive model (GAM)
    lossRegression loss for generalized additive model (GAM)

    Examples

    collapse all

    Reduce the size of a full generalized additive model (GAM) for regression by removing the training data. Full models hold the training data. You can use a compact model to improve memory efficiency.

    Load the carbig data set.

    load carbig

    Specify Acceleration, Displacement, Horsepower, and Weight as the predictor variables (X) and MPG as the response variable (Y).

    X = [Acceleration,Displacement,Horsepower,Weight];
    Y = MPG;

    Train a GAM using X and Y.

    Mdl = fitrgam(X,Y)
    Mdl = 
      RegressionGAM
                  ResponseName: 'Y'
         CategoricalPredictors: []
             ResponseTransform: 'none'
                     Intercept: 26.9442
        IsStandardDeviationFit: 0
               NumObservations: 398
    
    
      Properties, Methods
    
    

    Mdl is a RegressionGAM model object.

    Reduce the size of the model.

    CMdl = compact(Mdl)
    CMdl = 
      CompactRegressionGAM
                  ResponseName: 'Y'
         CategoricalPredictors: []
             ResponseTransform: 'none'
                     Intercept: 26.9442
        IsStandardDeviationFit: 0
    
    
      Properties, Methods
    
    

    CMdl is a CompactRegressionGAM model object.

    Display the amount of memory used by each regression model.

    whos('Mdl','CMdl')
      Name      Size             Bytes  Class                                          Attributes
    
      CMdl      1x1             578163  classreg.learning.regr.CompactRegressionGAM              
      Mdl       1x1             611957  RegressionGAM                                            
    

    The full model (Mdl) is larger than the compact model (CMdl).

    To efficiently predict responses for new observations, you can remove Mdl from the MATLAB® Workspace, and then pass CMdl and new predictor values to predict.

    Introduced in R2021a