ClassificationGAM
statistics: ClassificationGAM
Generalized additive model classification
The ClassificationGAM class implements a gradient boosting
algorithm for classification. This approach allows the model to capture
non-linear relationships between predictors and the binary response
variable.
Generalized additive model classification is a statistical method that extends linear models by allowing non-linear relationships between each predictor and the response variable through smooth functions. It combines the interpretability of linear models with the flexibility of non-parametric methods.
Create a ClassificationGAM object by using the fitcgam
function or the class constructor.
Two weak learners are available, selected by FitMethod.
'boostedtrees', the default, boosts one shallow decision tree per
predictor in each round, which is the scheme MATLAB’s generalized
additive model uses. A second phase then boosts trees over pairs of
predictors, where interactions are asked for.
'splines' boosts a smoothing spline per predictor over
NumIterations passes. It has no MATLAB counterpart and is an
Octave extension, kept because a smooth additive fit is a genuinely
different and often better answer than a staircase of stumps.
The two take different arguments, and an argument meant for one is refused by the other rather than ignored.
The choice is visible in the properties. Knots, Order,
DoF, Formula, LearningRate, NumIterations,
BaseModel, ModelwInt and IntMatrix describe a spline
fit and are empty under the boosted-tree engine, while
ModelParameters, ReasonForTermination, BinEdges,
PairDetectionBinEdges and TreeModel describe a tree fit and
are empty under the spline engine.
Fitted values are not expected to equal MATLAB’s even under
'boostedtrees'. The stopping rule and the step-reduction limit
are not recoverable from anything MATLAB reports, so this engine
documents its own; what the two share is the estimator and the reported
surface, not the arithmetic.
See also: fitcgam
Source Code: ClassificationGAM
The ClassificationGAM class contains the following properties:
A numeric matrix containing the unstandardized predictor data. Each column of X represents one predictor (variable), and each row represents one observation. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
Specified as a logical or numeric column vector, or as a character array or a cell array of character vectors with the same number of rows as the predictor data. Each row in Y is the observed class label for the corresponding row in X. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A positive integer value specifying the number of observations in the training dataset used for training the ClassificationGAM model. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A logical column vector with the same length as the observations in the
original predictor data X, true for each row that was used for
fitting the ClassificationGAM model. It is empty, [],
when every observation was used, so a non-empty value means that rows
holding missing values were dropped. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A positive integer value specifying the number of predictors in the training dataset used for training the ClassificationGAM model. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A cell array of character vectors specifying the names of the predictor variables. The names are in the order in which they appear in the training dataset. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A character vector specifying the name of the response variable Y. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
An array of unique values of the response variable Y, which has the
same data types as the data in Y. This property is read-only.
ClassNames can have any of the following datatypes:
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A 2-element numeric vector specifying the prior probabilities for each
class. The order of the elements in Prior corresponds to the
order of the classes in ClassNames. This property is read-only.
Specified as a row vector with one entry per class, in the order of
ClassNames, and rescaled to sum to one. It may be given as
'empirical', 'uniform', a numeric vector, or a
structure with ClassNames and ClassProbs fields, which
assigns each probability by class name rather than by position.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A character vector specifying the model formula in the form
'Y ~ terms' where Y represents the response variable and
terms specifies the predictor variables and interaction terms.
This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A Kx2 matrix of predictor index pairs, one row per two-way term
the model carries, and zeros (0, 2) when it carries none. It
reports what was fitted rather than what was asked for, so a count of
terms, 'all', a logical matrix and a formula all leave the same
kind of value behind. This property is read-only.
A main effect names one predictor and a higher-order term names three
or more, and neither has a two-column form, so neither appears here.
IntMatrix remains the complete record of every term fitted.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A scalar or row vector specifying the number of knots for each predictor variable in the spline fitting. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A scalar or row vector specifying the order of the spline for each predictor variable. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A scalar or row vector specifying the degrees of freedom for each predictor variable in the spline fitting. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A scalar value between 0 and 1 specifying the learning rate used in the gradient boosting algorithm. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A positive integer specifying the maximum number of iterations for the gradient boosting algorithm. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A numeric scalar, the log-odds of the response mean, which every additive term is measured against. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A numeric column vector with one entry per observation used for training, normalised to sum to one. This property is read-only.
Each class carries its prior spread evenly over its own observations,
so an observation of a class weighs Prior for that class
divided by the number of observations it holds.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A numeric vector holding the column of each predictor treated as categorical, and empty when none is. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A cell array of character vectors naming the predictors as the model
sees them. It matches PredictorNames unless a categorical
predictor was expanded into dummy variables. This property is
read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A structure containing the parameters of the base model without any interaction terms. The base model represents the generalized additive model with only the main effects (predictor terms) included. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A structure containing the parameters of the model that includes interaction terms. This model extends the base model by adding interaction terms between predictors. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A logical matrix with one row per term and one column per predictor, true wherever the term multiplies that predictor. A row naming one predictor is a main effect, two an interaction, and three or more a higher-order term. This property is read-only.
It is the complete record, where Interactions reports only the
two-way terms, in the form MATLAB reports them. It is also the form
the 'Interactions' option takes back, so passing it to the
constructor rebuilds a model over the same terms.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A cell array with one entry per predictor, holding that predictor’s bin edges where the model discretized it before fitting. It is empty here and stays empty: this generalized additive model is built from splines, which take the predictors as they are, where MATLAB’s is built from boosted trees and bins them. That difference is described in the class documentation.
This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A cell array with one row vector per predictor, holding the coarse cut points the residuals of the predictor phase were laid on while pairs were being tested. The grid is eight equal-frequency bins whatever the sample size, as MATLAB’s is. It is empty when the model carries no interaction terms, and empty throughout under the spline engine, which does not bin.
This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A structure holding the fitting parameters. Under the boosted-tree
engine it carries MATLAB’s own fields: NumPrint,
MaxPValue, InitialLearnRateForPredictors,
InitialLearnRateForInteractions,
NumTreesPerPredictor, NumTreesPerInteraction,
MaxNumSplitsPerPredictor, MaxNumSplitsPerInteraction,
VerbosityLevel, Interactions, Version,
Method and Type. Interactions here is the
request as it was made, a count or 'all', where the
Interactions property of the model is the pairs actually
selected.
Under the spline engine it describes that scheme instead, carrying
Knots, Order, DoF, Formula,
Interactions, LearningRate and NumIterations,
since none of the tree vocabulary applies to it.
This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A structure with the fields PredictorTrees and
InteractionTrees, each a character vector saying why that phase
of the fit ended: that it trained the trees it was asked for, or that
it could no longer improve the model. A phase that never ran reports
an empty character vector, which is what a model with no interaction
terms shows for the second field.
It is empty under the spline engine, which has no tree budget to exhaust.
This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A character vector, either 'boostedtrees' or
'splines'. The default is 'boostedtrees', which is the
scheme MATLAB’s generalized additive model uses and the one the
tree-shaped properties above describe.
'splines' selects the penalised-spline engine instead, which is
an Octave extension with no MATLAB counterpart. It is the scheme this
class fitted before version 1.9.0, and it is kept because a smooth
additive fit is a genuinely different and often better answer than a
staircase of stumps. The two engines take different arguments and an
argument meant for one is refused by the other rather than ignored.
This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A structure holding what the boosted-tree engine fitted, with fields
ShapeValues, one column vector per predictor giving that
predictor’s contribution in each of its bins, PairValues, one
matrix per selected pair, and Pairs, the predictor indices those
matrices belong to. A shape function is a step function, so these are
the whole of the fit however many trees produced them.
MATLAB exposes no equivalent: it reports the bin edges but never the
values on them, so its shape functions can only be reached through
predict. This property is an Octave extension, and it is empty
under the spline engine, whose fit lives in BaseModel and
ModelwInt.
This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
Always empty. It is declared for MATLAB compatibility, where it holds what an automatic search over the hyperparameters found. This class fits the parameters it is given and runs no such search, so there is nothing to report. This property is read-only.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
A square matrix specifying the cost of misclassification of a point.
Cost(i,j) is the cost of classifying a point into class j
if its true class is i (that is, the rows correspond to the true
class and the columns correspond to the predicted class). The order of
the rows and columns in Cost corresponds to the order of the
classes in ClassNames. The number of rows and columns in
Cost is the number of unique classes in the response. By
default, Cost(i,j) = 1 if i != j, and
Cost(i,j) = 0 if i = j. In other words, the cost is 0
for correct classification and 1 for incorrect classification.
Add or change the Cost property using dot notation as in:
obj.Cost = costMatrix
A cost may also be given as a struct with the fields
ClassNames and ClassificationCosts, which names the
order its own matrix is written in. That matrix is permuted into the
order of ClassNames above, so a caller need not know which
order the classes were sorted into. It must name every class.
A cost must be floating point, not sparse, not complex, non-negative
and zero down its diagonal, and must hold no NaN or
Inf. A single is widened to double.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
Specified as a function handle for transforming the classification
scores. Add or change the ScoreTransform property using dot
notation as in:
obj.ScoreTransform = 'function_name'
obj.ScoreTransform = @function_handle
When specified as a character vector, it can be any of the following
built-in functions. Nevertheless, the ScoreTransform property
always stores their function handle equivalent.
| Value | Description |
|---|---|
'doublelogit' | 1 ./ (1 + exp (-2 × x)) |
'invlogit' | log (x ./ (1 - x)) |
'ismax' | Sets the score for the class with the largest score to 1, and for all other classes to 0 |
'logit' | 1 ./ (1 + exp (-x)) |
'none' | x (no transformation) |
'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 for all other classes to -1 |
'symmetriclogit' | 2 ./ (1 + exp (-x)) - 1 |
The default is 'logit', as in MATLAB. This model’s raw
score is a log-odds, reported as the pair [-f, f] whose two
columns sum to zero, and the transform is what turns it into the
posterior probabilities that sum to one. Every transform therefore
composes on the log-odds and not on the probabilities, so
'none' returns the log-odds themselves.
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
The ClassificationGAM class offers the following public methods:
statistics: obj = ClassificationGAM (X, Y)
statistics: obj = ClassificationGAM (…, name, value)
obj = ClassificationGAM (X, Y) returns
a ClassificationGAM object, with X as the predictor data
and Y containing the class labels of observations in X.
X must be a N×P numeric matrix of input data where rows
correspond to observations and columns correspond to features or
variables. X will be used to train the GAM model.
Y is N×1 matrix or cell matrix containing the class labels
of corresponding predictor data in X. Y can contain any type
of categorical data. Y must have the same number of rows as
X.
obj = ClassificationGAM (…, name,
value) returns a ClassificationGAM object with parameters
specified by the following name, value paired input
arguments:
| Name | Value |
|---|---|
'PredictorNames' | A cell array of character vectors specifying the names of the predictors. The length of this array must match the number of columns in X. |
'ResponseName' | A character vector specifying the name of the response variable. |
'ClassNames' | Names of the classes in the class
labels, Y, used for fitting the GAM model.
ClassNames are of the same type as the class labels in Y. |
'Cost' | An N×R numeric matrix containing
misclassification cost for the corresponding instances in X, where
R is the number of unique categories in Y. If an instance
is correctly classified into its category the cost is calculated to be 1,
otherwise 0. The cost matrix can be altered by using
Mdl.cost = somecost. By default, its value is
cost = ones (rows (X), numel (unique (Y))). |
'Prior' | A numeric vector specifying the prior
probabilities for each class. The order of the elements in Prior
corresponds to the order of the classes in ClassNames.
Alternatively, you can specify 'empirical' to use the empirical
class probabilities or 'uniform' to assume equal class
probabilities. |
'ScoreTransform' | A user-defined function handle
or a character vector specifying one of the following builtin functions
specifying the transformation applied to predicted classification scores.
Supported values include 'doublelogit', 'invlogit',
'ismax', 'logit', 'none', 'identity',
'sign', 'symmetric', 'symmetricismax', and
'symmetriclogit'. |
'Formula' | (spline option) A character vector
specifying the model
formula in the form 'Y ~ terms' where Y represents the
response variable and terms specifies the predictor variables and
interaction terms. |
'Interactions' | A logical matrix, a positive
integer scalar, or the string 'all' for defining the interactions
between predictor variables. |
'Knots' | (spline option) A scalar or row vector specifying the number of knots for each predictor variable in the spline fitting. |
'Order' | (spline option) A scalar or row vector specifying the order of the spline for each predictor variable. |
'DoF' | (spline option) A scalar or row vector specifying the degrees of freedom for each predictor variable in the spline fitting. |
'LearningRate' | (spline option) A scalar value between 0 and 1 specifying the learning rate used in the gradient boosting algorithm. |
'NumIterations' | (spline option) A positive integer specifying the maximum number of iterations for the gradient boosting algorithm. |
A row marked (spline option) belongs to the spline
engine and requires 'FitMethod', 'splines'; passing one
under the default boosted-tree engine is an error rather than
being ignored. The boosted-tree engine’s own options are
documented under fitcgam.
See also: fitcgam
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: obj = addInteractions (obj, interactions)
obj = addInteractions (obj, interactions) fits
the interaction terms named by interactions on top of the terms
the model already carries and returns the updated model. The univariate
fit is left alone, so predict with
'IncludeInteractions' set false answers exactly as it
answered before.
interactions takes the forms the constructor’s
'Interactions' option takes: a nonnegative integer count of
terms, a logical matrix with a column per predictor, or 'all'.
A model already carrying interaction terms is not extended, which is
what MATLAB refuses too. A model fitted from a 'Formula' names
every term it has, interactions among them, and is refused for the same
reason.
Which terms a count selects is this implementation’s own: they are
taken in the order nchoosek lists the pairs, where MATLAB ranks
them by how much each contributes. The constructor’s option chooses
the same way, so the two agree with each other.
See also: fitcgam, ClassificationGAM
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: label = predict (obj, XC)
ClassificationGAM: [label, score] = predict (obj, XC)
ClassificationGAM: [label, score] = predict (…, 'IncludeInteractions', includeInteractions)
label = predict (obj, XC) returns the predicted
labels for the data in XC based on the model stored in the
ClassificationGAM object, obj.
[label, score] = predict (obj, XC) also
returns score, which contains the predicted class scores or
posterior probabilities for each observation.
[label, score] = predict (obj, XC,
'IncludeInteractions', includeInteractions) allows you to specify
whether interaction terms should be included when making predictions.
ClassificationGAM class object.
See also: ClassificationGAM, fitcgam
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: CVMdl = crossval (obj)
ClassificationGAM: CVMdl = crossval (…, name, value)
CVMdl = crossval (obj) returns a cross-validated model
object, CVMdl, from a trained model, obj, using 10-fold
cross-validation by default.
CVMdl = crossval (obj, name, value)
specifies additional name-value pair arguments to customize the
cross-validation process.
| Name | Value |
|---|---|
'KFold' | Specify the number of folds to use in
k-fold cross-validation. "KFold", k, where k is an
integer greater than 1. |
'Holdout' | Specify the fraction of the data to
hold out for testing. "Holdout", p, where p is a
scalar in the range (0,1). |
'Leaveout' | Specify whether to perform
leave-one-out cross-validation. "Leaveout", Value, where
Value is ’on’ or ’off’. |
'CVPartition' | Specify a cvpartition
object used for cross-validation. "CVPartition", cv, where
isa (cv, "cvpartition") = 1. |
See also: fitcgam, ClassificationGAM, cvpartition, ClassificationPartitionedModel
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: CVMdl = compact (obj)
CVMdl = compact (obj) creates a compact version of the
ClassificationGAM object, obj.
See also: fitcgam, ClassificationGAM, CompactClassificationGAM
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: m = margin (obj, X, Y)
m = margin (obj, X, Y) returns a column
vector holding, for each row of X, the score the model gives its
true class in Y less the score it gives the other class. A
positive margin means the observation is classified correctly, and the
larger it is the more confidently so.
See also: ClassificationGAM, edge, loss, predict
load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds, :); Y = species(inds); mdl = fitcgam (X, Y);
Positive wherever the model is right, and larger the more sure it is
m = margin (mdl, X, Y); [min(m), median(m), max(m)]
ans = 1 1 1
load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds, :); Y = species(inds); mdl = fitcgam (X, Y, 'NumTreesPerPredictor', 20);
Count the observations the model places on the wrong side
m = margin (mdl, X, Y); sum (m < 0)
ans = 0
ClassificationGAM: e = edge (obj, X, Y)
ClassificationGAM: e = edge (…, "Weights", w)
e = edge (obj, X, Y) returns the mean of
the classification margins over the rows of X.
e = edge (…, takes the
weighted mean instead, with one weight per row of X.
"Weights", w)
See also: ClassificationGAM, margin, loss, predict
load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds, :); Y = species(inds); mdl = fitcgam (X, Y); [edge(mdl, X, Y), mean(margin (mdl, X, Y))]
ans = 1 1
load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds, :); Y = species(inds); mdl = fitcgam (X, Y, 'NumTreesPerPredictor', 20);
Weighting the second class three times as heavily moves the mean
w = ones (rows (X), 1); w(strcmp (Y, 'virginica')) = 3; [edge(mdl, X, Y), edge(mdl, X, Y, 'Weights', w)]
ans = 0.9930 0.9930
ClassificationGAM: L = loss (obj, X, Y)
ClassificationGAM: L = loss (…, name, value)
L = loss (obj, X, Y) returns the loss of
the model on the rows of X against the true labels Y.
L = loss (…, name, value) accepts the
following name-value pairs:
"LossFun" selects the loss. Supported values are
"mincost", the default, "binodeviance",
"classifcost", "classiferror", "exponential",
"hinge", "logit" and "quadratic".
"mincost" assigns each observation to the class of least
expected cost and charges what that assignment costs, so it reads the
scores as a posterior, which is what this model returns;
"classifcost" charges what the model’s own prediction costs.
"Weights" holds one weight per row of X, normalised to
sum to one before it is applied.
See also: ClassificationGAM, margin, edge, predict
load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds, :); Y = species(inds); mdl = fitcgam (X, Y);
classiferror counts mistakes; mincost, the default, charges what the least costly assignment costs given the true class
[loss(mdl, X, Y, 'LossFun', 'classiferror'), loss(mdl, X, Y)]
ans = 0 0
load fisheriris inds = ! strcmp (species, 'setosa'); X = meas(inds, :); Y = species(inds); mdl = fitcgam (X, Y, 'NumTreesPerPredictor', 20);
Each is a function of the same margins, so they rank models alike but not on the same scale
names = {'classiferror', 'mincost', 'hinge', 'quadratic', 'logit'};
for i = 1:numel (names)
printf ("%-13s %.4f\n", names{i}, loss (mdl, X, Y, 'LossFun', names{i}));
endfor
classiferror 0.0000 mincost 0.0000 hinge 0.0035 quadratic 0.0001 logit 0.3142
load fisheriris inds = ! strcmp (species, 'virginica'); X = meas(inds, :); Y = species(inds); mdl = fitcgam (X, Y);
The same number, without handing the training data back in
[resubLoss(mdl), loss(mdl, X, Y)]
ans = 0 0
ClassificationGAM: label = resubPredict (obj)
ClassificationGAM: [label, score] = resubPredict (obj)
label = resubPredict (obj) is predict applied
to the observations the model was fitted on.
See also: ClassificationGAM, predict
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: m = resubMargin (obj)
See also: ClassificationGAM, margin
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: e = resubEdge (obj)
See also: ClassificationGAM, edge
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: L = resubLoss (obj)
ClassificationGAM: L = resubLoss (…, name, value)
See also: ClassificationGAM, loss
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: savemodel (obj, filename)
savemodel (obj, filename) saves each property of a
ClassificationGAM object into an Octave binary file, the name of which is
specified in filename, along with an extra variable, which defines
the type classification object these variables constitute. Use
loadmodel in order to load a classification object into Octave’s
workspace.
See also: loadmodel, fitcgam, ClassificationGAM
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
ClassificationGAM: Mdl = resume (obj, numTrees)
Mdl = resume (obj, numTrees) adds
numTrees more trees to obj and returns the result. The
original model is not modified.
Training continues in the phase that ran last, which is what MATLAB does: a model carrying interaction terms gains interaction trees and its predictor shape functions are left alone, while a model without them gains predictor trees. A round starts at its initial learning rate whatever its number, so the model this returns is the model a single fit of the combined budget would have produced.
numTrees must be a positive integer scalar. Resuming raises
where there is nothing left to gain, rather than returning the model
unchanged, and it is not available under
'FitMethod', 'splines': a backfit that has converged to its
tolerance has no budget to extend.
See also: ClassificationGAM, fitcgam, addInteractions
Train a GAM classifier for binary classification using specific data and plot the decision boundaries.
Define specific data
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);
X = [1, 2; 2, 3; 3, 3; 4, 5; 5, 5; ...
6, 7; 7, 8; 8, 8; 9, 9; 10, 10];
Y = [0; 0; 0; 0; 0; ...
1; 1; 1; 1; 1];
Train the GAM model
obj = fitcgam (X, Y, 'Interactions', 'all')
obj =
ClassificationGAM
ResponseName: 'Y'
ClassNames: [0 1]
ScoreTransform: 'logit'
NumObservations: 10
NumPredictors: 2
Interactions: [1x2 double]
Create a grid of values for prediction
x1 = [min(X(:,1)):0.1:max(X(:,1))]; x2 = [min(X(:,2)):0.1:max(X(:,2))]; [x1G, x2G] = meshgrid (x1, x2); XGrid = [x1G(:), x2G(:)]; [labels, score] = predict (obj, XGrid);