Main Content

CompactClassificationGAM

Compact generalized additive model (GAM) for binary classification

Since R2021a

    Description

    CompactClassificationGAM is a compact version of a ClassificationGAM model object (GAM for binary classification). The compact model does not include the data used for training the classifier. Therefore, you cannot perform some tasks, such as cross-validation, using the compact model. Use a compact model for tasks such as predicting the labels of new data.

    Creation

    Create a CompactClassificationGAM object from a full ClassificationGAM 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

    Other Classification 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.

    Unique class labels used in training, specified as a categorical or character array, logical or numeric vector, or cell array of character vectors. ClassNames has the same data type as the class labels Y. (The software treats string arrays as cell arrays of character vectors.) ClassNames also determines the class order.

    Data Types: single | double | logical | char | cell | categorical

    Misclassification costs, specified as a 2-by-2 numeric matrix.

    Cost(i,j) is the cost of classifying a point into class j if its true class is i. The order of the rows and columns of Cost corresponds to the order of the classes in ClassNames.

    The software uses the Cost value for prediction, but not training. You can change the value by using dot notation.

    Example: Mdl.Cost = C;

    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 in PredictorNames corresponds to the order in which the predictor names appear in the training data.

    Data Types: cell

    This property is read-only.

    Prior class probabilities, specified as a numeric vector with two elements. The order of the elements corresponds to the order of the elements in ClassNames.

    Data Types: double

    This property is read-only.

    Response variable name, specified as a character vector.

    Data Types: char

    Score transformation, specified as a character vector or function handle. ScoreTransform represents a built-in transformation function or a function handle for transforming predicted classification scores.

    To change the score transformation function to function, for example, use dot notation.

    • For a built-in function, enter a character vector.

      Mdl.ScoreTransform = 'function';

      This table describes the available built-in functions.

      ValueDescription
      'doublelogit'1/(1 + e–2x)
      'invlogit'log(x / (1 – x))
      'ismax'Sets the score for the class with the largest score to 1, and sets the scores for all other classes to 0
      'logit'1/(1 + ex)
      'none' or 'identity'x (no transformation)
      'sign'–1 for x < 0
      0 for x = 0
      1 for x > 0
      'symmetric'2x – 1
      'symmetricismax'Sets the score for the class with the largest score to 1, and sets the scores for all other classes to –1
      'symmetriclogit'2/(1 + ex) – 1

    • For a MATLAB® function or a function that you define, enter its function handle.

      Mdl.ScoreTransform = @function;

      function must accept a matrix (the original scores) and return a matrix of the same size (the transformed scores).

    This property determines the output score computation for object functions such as predict, margin, and edge. Use 'logit' to compute posterior probabilities, and use 'none' to compute the logit of posterior probabilities.

    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
    predictClassify observations using generalized additive model (GAM)
    lossClassification loss for generalized additive model (GAM)
    marginClassification margins for generalized additive model (GAM)
    edgeClassification edge for generalized additive model (GAM)
    compareHoldoutCompare accuracies of two classification models using new data

    Examples

    collapse all

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

    Load the ionosphere data set. This data set has 34 predictors and 351 binary responses for radar returns, either bad ('b') or good ('g').

    load ionosphere

    Train a GAM using the predictors X and class labels Y. A recommended practice is to specify the class names.

    Mdl = fitcgam(X,Y,'ClassNames',{'b','g'})
    Mdl = 
      ClassificationGAM
                 ResponseName: 'Y'
        CategoricalPredictors: []
                   ClassNames: {'b'  'g'}
               ScoreTransform: 'logit'
                    Intercept: 2.2715
              NumObservations: 351
    
    
    

    Mdl is a ClassificationGAM model object.

    Reduce the size of the classifier.

    CMdl = compact(Mdl)
    CMdl = 
      CompactClassificationGAM
                 ResponseName: 'Y'
        CategoricalPredictors: []
                   ClassNames: {'b'  'g'}
               ScoreTransform: 'logit'
                    Intercept: 2.2715
    
    
    

    CMdl is a CompactClassificationGAM model object.

    Display the amount of memory used by each classifier.

    whos('Mdl','CMdl')
      Name      Size              Bytes  Class                                                 Attributes
    
      CMdl      1x1             1030188  classreg.learning.classif.CompactClassificationGAM              
      Mdl       1x1             1231165  ClassificationGAM                                               
    

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

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

    Version History

    Introduced in R2021a