main content

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

linear regression properties

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

regularization term strength, specified as a nonnegative scalar or vector of nonnegative values.

data types: double | single

linear regression model type, specified as 'leastsquares' or 'svm'.

in this table, f(x)=xβ b.

  • β is a vector of p coefficients.

  • x is an observation from p predictor variables.

  • b is the scalar bias.

valuealgorithmloss functionfittedloss value
'svm'support vector machine regressionepsilon insensitive: [y,f(x)]=max[0,|yf(x)|ε]'epsiloninsensitive'
'leastsquares'linear regression through ordinary least squaresmean squared error (mse): [y,f(x)]=12[yf(x)]2'mse'

linear coefficient estimates, specified as a numeric vector with length equal to the number of predictors.

data types: double

estimated bias term or model intercept, specified as a numeric scalar.

data types: double

loss function used to fit the model, specified as 'epsiloninsensitive' or 'mse'.

valuealgorithmloss functionlearner value
'epsiloninsensitive'support vector machine regressionepsilon insensitive: [y,f(x)]=max[0,|yf(x)|ε]'svm'
'mse'linear regression through ordinary least squaresmean squared error (mse): [y,f(x)]=12[yf(x)]2'leastsquares'

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.

valuedescription
'lasso (l1)'lasso (l1) penalty: λj=1p|βj|
'ridge (l2)'ridge (l2) penalty: λ2j=1pβj2

λ specifies the regularization term strength (see lambda).

the software excludes the bias term (β0) from the regularization penalty.

other regression properties

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

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

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

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

response variable name, specified as a character vector.

data types: char

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
limelocal interpretable model-agnostic explanations (lime)
regression loss for linear regression models
partialdependencecompute partial dependence
plotpartialdependencecreate partial dependence plot (pdp) and individual conditional expectation (ice) plots
predict response of linear regression model
select fitted regularized linear regression models
shapleyshapley values
updateupdate model parameters for code generation

copy semantics

value. to learn how value classes affect copy operations, see .

examples

train a linear regression model using svm, dual sgd, and ridge regularization.

simulate 10000 observations from this model

y=x100 2x200 e.

  • x=x1,...,x1000 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.

simulate 10000 observations from this model

y=x100 2x200 e.

  • x={x1,...,x1000} 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

version history

introduced in r2016a

see also

| |

网站地图