# CompactClassificationGAM

Compact generalized additive model (GAM) for binary classification

## 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

### GAM Properties

`Interactions`

— Interaction term indices

two-column matrix of positive integers | `[]`

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`

`Intercept`

— Intercept term of model

numeric scalar

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

`CategoricalPredictors`

— Categorical predictor indices

vector of positive integers | `[]`

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`

`ClassNames`

— Unique class labels

categorical array | character array | logical vector | numeric vector | cell array of character vectors

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`

`Cost`

— Misclassification costs

2-by-2 numeric matrix

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

`Cost(`

is the cost of classifying a point into class * i*,

*)*

`j`

*if its true class is*

`j`

*. The order of the rows and columns of*

`i`

`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`

`ExpandedPredictorNames`

— Expanded predictor names

cell array of character vectors

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`

`PredictorNames`

— Predictor variable names

cell array of character vectors

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`

`Prior`

— Prior class probabilities

numeric vector

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`

`ResponseName`

— Response variable name

character vector

This property is read-only.

Response variable name, specified as a character vector.

**Data Types: **`char`

`ScoreTransform`

— Score transformation

character vector | function handle

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.

Value Description `'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 + *e*^{–x})`'none'`

or`'identity'`

*x*(no transformation)`'sign'`

–1 for *x*< 0

0 for*x*= 0

1 for*x*> 0`'symmetric'`

2 *x*– 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 + *e*^{–x}) – 1For a MATLAB

^{®}function or a function that you define, enter its function handle.Mdl.ScoreTransform = @

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

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

### Interpret Prediction

`lime` | Local interpretable model-agnostic explanations (LIME) |

`partialDependence` | Compute partial dependence |

`plotLocalEffects` | Plot local effects of terms in generalized additive model (GAM) |

`plotPartialDependence` | Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots |

`shapley` | Shapley values |

### Assess Predictive Performance on New Observations

### Compare Accuracies

`compareHoldout` | Compare accuracies of two classification models using new data |

## Examples

### Reduce Size of Generalized Additive Model

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 Properties, Methods

`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 Properties, Methods

`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 1030019 classreg.learning.classif.CompactClassificationGAM Mdl 1x1 1230996 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`

.

**Introduced in R2021a**

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

# Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)