Compact linear regression model
CompactLinearModel
is a compact version of a full linear
regression model object LinearModel
. Because a compact model does
not store the input data used to fit the model or information related to the fitting
process, a CompactLinearModel
object consumes less memory than a
LinearModel
object. You can still use a compact model to predict
responses using new input data, but some LinearModel
object functions
do not work with a compact model.
Create a CompactLinearModel
model from a full, trained LinearModel
model by using compact
.
CoefficientCovariance
— Covariance matrix of coefficient estimatesThis property is readonly.
Covariance matrix of coefficient estimates, specified as a pbyp matrix of numeric values. p is the number of coefficients in the fitted model.
For details, see Coefficient Standard Errors and Confidence Intervals.
Data Types: single
 double
CoefficientNames
— Coefficient namesThis property is readonly.
Coefficient names, specified as a cell array of character vectors, each containing the name of the corresponding term.
Data Types: cell
Coefficients
— Coefficient valuesThis property is readonly.
Coefficient values, specified as a table.
Coefficients
contains one row for each coefficient and these
columns:
Estimate
— Estimated
coefficient value
SE
— Standard error
of the estimate
tStat
— tstatistic for a test that the
coefficient is zero
pValue
— pvalue for the
tstatistic
Use anova
(only for a linear regression model) or
coefTest
to perform other tests on the coefficients. Use
coefCI
to find the confidence intervals of the coefficient
estimates.
To obtain any of these columns as a vector, index into the property
using dot notation. For example, obtain the estimated coefficient vector in the model
mdl
:
beta = mdl.Coefficients.Estimate
Data Types: table
NumCoefficients
— Number of model coefficientsThis property is readonly.
Number of model coefficients, specified as a positive integer.
NumCoefficients
includes coefficients that are set to zero when
the model terms are rank deficient.
Data Types: double
NumEstimatedCoefficients
— Number of estimated coefficientsThis property is readonly.
Number of estimated coefficients in the model, specified as a positive integer.
NumEstimatedCoefficients
does not include coefficients that are
set to zero when the model terms are rank deficient.
NumEstimatedCoefficients
is the degrees of freedom for
regression.
Data Types: double
DFE
— Degrees of freedom for errorThis property is readonly.
Degrees of freedom for the error (residuals), equal to the number of observations minus the number of estimated coefficients, specified as a positive integer.
Data Types: double
LogLikelihood
— LoglikelihoodThis property is readonly.
Loglikelihood of response values, specified as a numeric value, based
on the assumption that each response value follows a normal
distribution. The mean of the normal distribution is the fitted
(predicted) response value, and the variance is the
MSE
.
Data Types: single
 double
ModelCriterion
— Criterion for model comparisonThis property is readonly.
Criterion for model comparison, specified as a structure with these fields:
AIC
— Akaike information criterion.
AIC = –2*logL + 2*m
, where logL
is the
loglikelihood and m
is the number of estimated
parameters.
AICc
— Akaike information criterion corrected for
the sample size. AICc = AIC + (2*m*(m + 1))/(n – m – 1)
,
where n
is the number of observations.
BIC
— Bayesian information criterion.
BIC = –2*logL + m*log(n)
.
CAIC
— Consistent Akaike information criterion.
CAIC = –2*logL + m*(log(n) + 1)
.
Information criteria are model selection tools that you can use to compare multiple models fit to the same data. These criteria are likelihoodbased measures of model fit that include a penalty for complexity (specifically, the number of parameters). Different information criteria are distinguished by the form of the penalty.
When you compare multiple models, the model with the lowest information criterion value is the bestfitting model. The bestfitting model can vary depending on the criterion used for model comparison.
To obtain any of the criterion values as a scalar, index into the property using dot
notation. For example, obtain the AIC value aic
in the model
mdl
:
aic = mdl.ModelCriterion.AIC
Data Types: struct
MSE
— Mean squared errorThis property is readonly.
Mean squared error (residuals), specified as a numeric value.
MSE = SSE / DFE,
where MSE is the mean squared error, SSE is the sum of squared errors, and DFE is the degrees of freedom.
Data Types: single
 double
RMSE
— Root mean squared errorThis property is readonly.
Root mean squared error (residuals), specified as a numeric value.
RMSE = sqrt(MSE),
where RMSE is the root mean squared error and MSE is the mean squared error.
Data Types: single
 double
Rsquared
— Rsquared value for modelThis property is readonly.
Rsquared value for the model, specified as a structure with two fields:
Ordinary
— Ordinary (unadjusted) Rsquared
Adjusted
— Rsquared adjusted for the number of
coefficients
The Rsquared value is the proportion of the total sum of squares explained by the
model. The ordinary Rsquared value relates to the SSR
and
SST
properties:
Rsquared = SSR/SST
,
where SST
is the total sum of squares, and
SSR
is the regression sum of squares.
For details, see Coefficient of Determination (RSquared).
To obtain either of these values as a scalar, index into the property using dot
notation. For example, obtain the adjusted Rsquared value in the model
mdl
:
r2 = mdl.Rsquared.Adjusted
Data Types: struct
SSE
— Sum of squared errorsThis property is readonly.
Sum of squared errors (residuals), specified as a numeric value.
The Pythagorean theorem implies
SST = SSE + SSR
,
where SST
is the total sum of squares,
SSE
is the sum of squared errors, and SSR
is
the regression sum of squares.
Data Types: single
 double
SSR
— Regression sum of squaresThis property is readonly.
Regression sum of squares, specified as a numeric value. The regression sum of squares is equal to the sum of squared deviations of the fitted values from their mean.
The Pythagorean theorem implies
SST = SSE +
SSR
,
where SST
is the total sum
of squares, SSE
is the sum of squared errors,
and SSR
is the regression sum of
squares.
Data Types: single
 double
SST
— Total sum of squaresThis property is readonly.
Total sum of squares, specified as a numeric value. The total sum of squares is equal
to the sum of squared deviations of the response vector y
from the
mean(y)
.
The Pythagorean theorem implies
SST = SSE + SSR
,
where SST
is the total sum of squares,
SSE
is the sum of squared errors, and SSR
is
the regression sum of squares.
Data Types: single
 double
Robust
— Robust fit informationThis property is readonly.
Robust fit information, specified as a structure with the fields described in this table.
Field  Description 

WgtFun  Robust weighting function, such as 'bisquare' (see
'RobustOpts' ) 
Tune  Tuning constant. This field is empty ([] ) if
WgtFun is 'ols' or if
WgtFun is a function handle for a custom weight
function with the default tuning constant 1. 
Weights  Vector of weights used in the final iteration of robust fit. This
field is empty for a CompactLinearModel
object. 
This structure is empty unless you fit the model using robust regression.
Data Types: struct
Formula
— Model informationLinearFormula
objectThis property is readonly.
Model information, specified as a LinearFormula
object.
Display the formula of the fitted model mdl
using dot
notation:
mdl.Formula
NumObservations
— Number of observationsThis property is readonly.
Number of observations the fitting function used in fitting, specified
as a positive integer. NumObservations
is the
number of observations supplied in the original table, dataset,
or matrix, minus any excluded rows (set with the
'Exclude'
namevalue pair
argument) or rows with missing values.
Data Types: double
NumPredictors
— Number of predictor variablesThis property is readonly.
Number of predictor variables used to fit the model, specified as a positive integer.
Data Types: double
NumVariables
— Number of variablesThis property is readonly.
Number of variables in the input data, specified as a positive integer.
NumVariables
is the number of variables in the original table or
dataset, or the total number of columns in the predictor matrix and response
vector.
NumVariables
also includes any variables that are not used to fit
the model as predictors or as the response.
Data Types: double
PredictorNames
— Names of predictors used to fit modelThis property is readonly.
Names of predictors used to fit the model, specified as a cell array of character vectors.
Data Types: cell
ResponseName
— Response variable nameThis property is readonly.
Response variable name, specified as a character vector.
Data Types: char
VariableInfo
— Information about variablesThis property is readonly.
Information about variables contained in Variables
, specified as a
table with one row for each variable and the columns described in this table.
Column  Description 

Class  Variable class, specified as a cell array of character vectors, such
as 'double' and
'categorical' 
Range  Variable range, specified as a cell array of vectors

InModel  Indicator of which variables are in the fitted model, specified as a
logical vector. The value is true if the model
includes the variable. 
IsCategorical  Indicator of categorical variables, specified as a logical vector.
The value is true if the variable is
categorical. 
VariableInfo
also includes any variables that are not used to fit
the model as predictors or as the response.
Data Types: table
VariableNames
— Names of variablesThis property is readonly.
Names of variables, specified as a cell array of character vectors.
If the fit is based on a table or dataset, this property provides the names of the variables in the table or dataset.
If the fit is based on a predictor matrix and response vector,
VariableNames
contains the values specified by the
'VarNames'
namevalue pair argument of the fitting
method. The default value of 'VarNames'
is
{'x1','x2',...,'xn','y'}
.
VariableNames
also includes any variables that are not used to fit
the model as predictors or as the response.
Data Types: cell
anova  Analysis of variance for linear regression model 
coefCI  Confidence intervals of coefficient estimates of linear regression model 
coefTest  Linear hypothesis test on linear regression model coefficients 
partialDependence  Compute partial dependence 
plotEffects  Plot main effects of predictors in linear regression model 
plotInteraction  Plot interaction effects of two predictors in linear regression model 
plotPartialDependence  Create partial dependence plot (PDP) and individual conditional expectation (ICE) plots 
plotSlice  Plot of slices through fitted linear regression surface 
gather  Gather properties of Statistics and Machine Learning Toolbox object from GPU 
Fit a linear regression model to data and reduce the size of a full, fitted linear regression model by discarding the sample data and some information related to the fitting process.
Load the largedata4reg
data set, which contains 15,000 observations and 45 predictor variables.
load largedata4reg
Fit a linear regression model to the data.
mdl = fitlm(X,Y);
Compact the model.
compactMdl = compact(mdl);
The compact model discards the original sample data and some information related to the fitting process.
Compare the size of the full model mdl
and the compact model compactMdl
.
vars = whos('compactMdl','mdl'); [vars(1).bytes,vars(2).bytes]
ans = 1×2
81537 11408528
The compact model consumes less memory than the full model.
Usage notes and limitations:
For more information, see Introduction to Code Generation.
Usage notes and limitations:
The following object functions fully support GPU arrays:
The following object functions support model objects fitted with GPU array input arguments:
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Vous possédez une version modifiée de cet exemple. Souhaitezvous ouvrir cet exemple avec vos modifications ?
Vous avez cliqué sur un lien qui correspond à cette commande MATLAB :
Pour exécuter la commande, saisissezla dans la fenêtre de commande de MATLAB. Les navigateurs web ne supportent pas les commandes MATLAB.
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: .
Select web siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.