linear regression model for high-凯发k8网页登录
linear regression model for high-dimensional data
description
regressionlinear
is a trained linear model object for regression; the linear model is a support vector machine regression (svm) or linear regression model. fitrlinear
fits a regressionlinear
model by minimizing the objective function using techniques that reduce computation time for high-dimensional data sets (e.g., stochastic gradient descent). the regression loss plus the regularization term compose the objective function.
unlike other regression models, and for economical memory usage, regressionlinear
model objects do not store the training data. however, they do store, for example, the estimated linear model coefficients, estimated coefficients, and the regularization strength.
you can use trained regressionlinear
models to predict responses for new data. for details, see .
construction
create a regressionlinear
object by using fitrlinear
.
properties
epsilon
— half of width of epsilon-insensitive band
nonnegative scalar
half of the width of the epsilon insensitive band, specified as a nonnegative scalar.
if learner
is not 'svm'
, then epsilon
is an empty array ([]
).
data types: single
| double
lambda
— regularization term strength
nonnegative scalar | vector of nonnegative values
regularization term strength, specified as a nonnegative scalar or vector of nonnegative values.
data types: double
| single
learner
— linear regression model type
'leastsquares'
| 'svm'
linear regression model type, specified as 'leastsquares'
or 'svm'
.
in this table,
β is a vector of p coefficients.
x is an observation from p predictor variables.
b is the scalar bias.
value | algorithm | loss function | fittedloss value |
---|---|---|---|
'svm' | support vector machine regression | epsilon insensitive: | 'epsiloninsensitive' |
'leastsquares' | linear regression through ordinary least squares | mean squared error (mse): | 'mse' |
beta
— linear coefficient estimates
numeric vector
linear coefficient estimates, specified as a numeric vector with length equal to the number of predictors.
data types: double
bias
— estimated bias term
numeric scalar
estimated bias term or model intercept, specified as a numeric scalar.
data types: double
fittedloss
— loss function used to fit the linear model
'epsiloninsensitive'
| 'mse'
loss function used to fit the model, specified as 'epsiloninsensitive'
or 'mse'
.
value | algorithm | loss function | learner value |
---|---|---|---|
'epsiloninsensitive' | support vector machine regression | epsilon insensitive: | 'svm' |
'mse' | linear regression through ordinary least squares | mean squared error (mse): | 'leastsquares' |
regularization
— complexity penalty type
'lasso (l1)'
| 'ridge (l2)'
complexity penalty type, specified as 'lasso (l1)'
or 'ridge
(l2)'
.
the software composes the objective function for minimization from the sum of the average loss
function (see fittedloss
) and a regularization value from this
table.
value | description |
---|---|
'lasso (l1)' | lasso (l1) penalty: |
'ridge (l2)' | ridge (l2) penalty: |
λ specifies the regularization term
strength (see lambda
).
the software excludes the bias term (β0) from the regularization penalty.
categoricalpredictors
— categorical predictor indices
vector of positive integers | []
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: single
| double
modelparameters
— parameters used for training model
structure
parameters used for training the regressionlinear
model, specified as a structure.
access fields of modelparameters
using dot notation. for example, access
the relative tolerance on the linear coefficients and the bias term by using
mdl.modelparameters.betatolerance
.
data types: struct
predictornames
— predictor names
cell array of character vectors
predictor names in order of their appearance in the predictor data, specified as a
cell array of character vectors. the length of predictornames
is
equal to the number of variables in the training data x
or
tbl
used as predictor variables.
data types: cell
expandedpredictornames
— expanded predictor names
cell array of character vectors
expanded predictor names, specified as a cell array of character vectors.
if the model uses encoding for categorical variables, then
expandedpredictornames
includes the names that describe the
expanded variables. otherwise, expandedpredictornames
is the same as
predictornames
.
data types: cell
responsename
— response variable name
character vector
response variable name, specified as a character vector.
data types: char
responsetransform
— response transformation function
'none'
| function handle
response transformation function, specified as 'none'
or a function handle.
responsetransform
describes how the software transforms raw
response values.
for a matlab® function or a function that you define, enter its function handle. for
example, you can enter mdl.responsetransform =
@function
, where
function
accepts a numeric vector of the
original responses and returns a numeric vector of the same size containing the
transformed responses.
data types: char
| function_handle
object functions
convert linear regression model to incremental learner | |
lime | local interpretable model-agnostic explanations (lime) |
regression loss for linear regression models | |
partialdependence | compute partial dependence |
plotpartialdependence | create partial dependence plot (pdp) and individual conditional expectation (ice) plots |
predict response of linear regression model | |
select fitted regularized linear regression models | |
shapley | shapley values |
update | update model parameters for code generation |
copy semantics
value. to learn how value classes affect copy operations, see .
examples
train linear regression model
train a linear regression model using svm, dual sgd, and ridge regularization.
simulate 10000 observations from this model
is a 10000-by-1000 sparse matrix with 10% nonzero standard normal elements.
e is random normal error with mean 0 and standard deviation 0.3.
rng(1) % for reproducibility
n = 1e4;
d = 1e3;
nz = 0.1;
x = sprandn(n,d,nz);
y = x(:,100) 2*x(:,200) 0.3*randn(n,1);
train a linear regression model. by default, fitrlinear
uses support vector machines with a ridge penalty, and optimizes using dual sgd for svm. determine how well the optimization algorithm fit the model to the data by extracting a fit summary.
[mdl,fitinfo] = fitrlinear(x,y)
mdl = regressionlinear responsename: 'y' responsetransform: 'none' beta: [1000x1 double] bias: -0.0056 lambda: 1.0000e-04 learner: 'svm' properties, methods
fitinfo = struct with fields:
lambda: 1.0000e-04
objective: 0.2725
passlimit: 10
numpasses: 10
batchlimit: []
numiterations: 100000
gradientnorm: nan
gradienttolerance: 0
relativechangeinbeta: 0.4907
betatolerance: 1.0000e-04
deltagradient: 1.5816
deltagradienttolerance: 0.1000
terminationcode: 0
terminationstatus: {'iteration limit exceeded.'}
alpha: [10000x1 double]
history: []
fittime: 0.0331
solver: {'dual'}
mdl
is a regressionlinear
model. you can pass mdl
and the training or new data to loss
to inspect the in-sample mean-squared error. or, you can pass mdl
and new predictor data to predict
to predict responses for new observations.
fitinfo
is a structure array containing, among other things, the termination status (terminationstatus
) and how long the solver took to fit the model to the data (fittime
). it is good practice to use fitinfo
to determine whether optimization-termination measurements are satisfactory. in this case, fitrlinear
reached the maximum number of iterations. because training time is fast, you can retrain the model, but increase the number of passes through the data. or, try another solver, such as lbfgs.
predict responses using linear regression model
simulate 10000 observations from this model
is a 10000-by-1000 sparse matrix with 10% nonzero standard normal elements.
e is random normal error with mean 0 and standard deviation 0.3.
rng(1) % for reproducibility
n = 1e4;
d = 1e3;
nz = 0.1;
x = sprandn(n,d,nz);
y = x(:,100) 2*x(:,200) 0.3*randn(n,1);
hold out 5% of the data.
rng(1); % for reproducibility cvp = cvpartition(n,'holdout',0.05)
cvp = hold-out cross validation partition numobservations: 10000 numtestsets: 1 trainsize: 9500 testsize: 500
cvp
is a cvpartition
object that defines the random partition of n data into training and test sets.
train a linear regression model using the training set. for faster training time, orient the predictor data matrix so that the observations are in columns.
idxtrain = training(cvp); % extract training set indices x = x'; mdl = fitrlinear(x(:,idxtrain),y(idxtrain),'observationsin','columns');
predict observations and the mean squared error (mse) for the hold out sample.
idxtest = test(cvp); % extract test set indices yhat = predict(mdl,x(:,idxtest),'observationsin','columns'); l = loss(mdl,x(:,idxtest),y(idxtest),'observationsin','columns')
l = 0.1851
the hold-out sample mse is 0.1852.
extended capabilities
c/c code generation
generate c and c code using matlab® coder™.
usage notes and limitations:
the and
update
functions support code generation.when you train a linear regression model by using
fitrlinear
, the following restrictions apply.if the predictor data input argument value is a matrix, it must be a full, numeric matrix. code generation does not support sparse data.
you can specify only one regularization strength, either
'auto'
or a nonnegative scalar for the'lambda'
name-value pair argument.the value of the
'responsetransform'
name-value pair argument cannot be an anonymous function.code generation with a coder configurer does not support categorical predictors (
logical
,categorical
,char
,string
, orcell
). you cannot use the'categoricalpredictors'
name-value argument. to include categorical predictors in a model, preprocess them by using before fitting the model.
for more information, see introduction to code generation.
version history
introduced in r2016a
see also
| fitrlinear
|
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
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
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)