CompactRegressionGAM
statistics: CompactRegressionGAM
Compact generalized additive model regression
The CompactRegressionGAM class implements a compact version of the
generalized additive model regression object, which predicts responses for
new data with the predict method but does not store the training
data.
A compact model consumes less memory than the full RegressionGAM
model, but cannot perform tasks that need the training data, such as
computing a resubstitution loss or the standard deviation of a prediction.
Create a CompactRegressionGAM object by using the compact
method on a RegressionGAM object.
The engine that fitted the model is carried over in FitMethod,
and the compact model predicts by the same scheme the full one did.
Under 'boostedtrees', the default, the fit is described by
TreeModel, BinEdges and PairDetectionBinEdges.
Under 'splines' it is described by Formula,
BaseModel, ModelwInt and IntMatrix, which MATLAB’s
compact model does not carry.
Whichever fitted the model, the other set is empty. A standard
deviation is available from the spline engine alone.
See also: RegressionGAM, fitrgam
Source Code: CompactRegressionGAM
The CompactRegressionGAM class contains the following properties:
A positive integer, the number of predictors of the training data. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A cell array of character vectors naming the predictors, in the order they appear in the training data. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A character vector naming the response variable Y. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A numeric vector holding the column of each predictor treated as categorical, and empty when none is. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
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.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A numeric scalar, the mean of the response, which every additive term is measured against. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A character vector naming the response and the terms of the model, as
in 'Y ~ x1 + x2 + x1:x2', or empty when the model was not
given one. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A 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.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A boolean flag, always false, as this class estimates the
standard deviation of a prediction from the residuals of the fit
rather than fitting a model for it. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A structure holding the intercept, the piecewise polynomial of each predictor, the number of backfitting cycles, the residuals and the residual sum of squares of the model fitted without interaction terms. This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A structure of the same fields as BaseModel, for the model
fitted with the interaction terms, and empty when none was asked for.
This property is read-only.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
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.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
A function handle applied to the response the model predicts. Add or
change it using dot notation, as in
obj.ResponseTransform = 'log' or
obj.ResponseTransform = @function_handle. It defaults
to 'none', the identity.
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
The CompactRegressionGAM class offers the following public methods:
CompactRegressionGAM: yFit = predict (obj, Xfit)
CompactRegressionGAM: yFit = predict (…, Name, Value)
CompactRegressionGAM: [yFit, ySD, yInt] = predict (…)
yFit = predict (obj, Xfit returns a vector of
predicted responses, yFit, for the predictor data in matrix
Xfit based on the Generalized Additive Model in obj.
Xfit must have the same number of features/variables as the
training data in obj.
CompactRegressionGAM class object.
[yFit, ySD, yInt] = predict (obj,
Xfit
also returns the standard deviations, ySD, and prediction
intervals,
yInt, of the response variable yFit, evaluated at each
observation in the predictor data Xfit.
yFit = predict (…, Name, Value) returns
the
aforementioned results with additional properties specified by
Name-Value pair arguments listed below.
| Name | Value |
|---|---|
'alpha' | significance level of the prediction
intervals yInt, specified as scalar in range [0,1]. The
default value is 0.05, which corresponds to 95% prediction intervals. |
'includeinteractions' | a boolean flag to include
interactions to predict new values based on Xfit. By default,
'includeinteractions' is true when the GAM model in
obj
contains a obj.Formula or obj.Interactions fields.
Otherwise, is set to false. If set to true when no
interactions are present in the trained model, it will result to an
error. If set to
false when using a model that includes interactions, the
predictions
will be made on the basic model without any interaction terms. This way
you can make predictions from the same GAM model without having to
retrain it. |
See also: fitrgam, RegressionGAM
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y); cmdl = compact (mdl);
No X on the compact model, and the same fitted values out of it
[isprop(mdl, 'X'), isprop(cmdl, 'X'), ... max(abs (predict (mdl, X) - predict (cmdl, X)))]
ans = 1 0 0
load fisheriris X = meas(:,1:3); Y = meas(:,4); cmdl = compact (fitrgam (X, Y));
loss is available without the training data
loss (cmdl, X, Y)
ans = 0.016330
CompactRegressionGAM: L = loss (obj, X, Y)
CompactRegressionGAM: L = loss (…, name, value)
L = loss (obj, X, Y) returns the weighted
mean squared error of the model on the rows of X against the true
response Y.
L = loss (…, name, value) accepts the
following name-value pairs:
"LossFun" selects the loss, either "mse", the default,
or a function handle taking the true response, the predicted response
and the weights, and returning a numeric scalar.
"Weights" holds one weight per row of X, normalised to
sum to one before it is applied.
See also: CompactRegressionGAM, RegressionGAM, fitrgam, predict
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
CompactRegressionGAM: savemodel (obj, filename)
savemodel (obj, filename) saves each property of a
CompactRegressionGAM object into an Octave binary file, the name of
which is specified in filename, along with an extra variable which
defines the type of object these variables constitute. Use
loadmodel in order to load the object back into Octave.
See also: loadmodel, fitrgam, RegressionGAM
Take the compact version of a fitted model and predict with it
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
load fisheriris X = meas(:,1:3); Y = meas(:,4); mdl = fitrgam (X, Y)
mdl =
RegressionGAM
ResponseName: 'Y'
NumObservations: 150
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933
Knots: []
Order: []
Tol:
cmdl = compact (mdl)
cmdl =
CompactRegressionGAM
ResponseName: 'Y'
NumPredictors: 3
ResponseTransform: 'none'
Intercept: 1.19933