Class: LinearModel

Predict response of linear regression model


ypred = predict(mdl,Xnew)
[ypred,yci] = predict(mdl,Xnew)
[ypred,yci] = predict(mdl,Xnew,Name,Value)


ypred = predict(mdl,Xnew) returns the predicted response of the mdl linear regression model to the points in Xnew.

[ypred,yci] = predict(mdl,Xnew) returns confidence intervals for the true mean responses.

[ypred,yci] = predict(mdl,Xnew,Name,Value) predicts responses with additional options specified by one or more Name,Value pair arguments.


  • For predictions with added noise, use random.

Input Arguments


Linear model, as constructed by fitlm or stepwiselm.


Points at which mdl predicts responses.

  • If Xnew is a table or dataset array, it must contain the predictor names in mdl.

  • If Xnew is a numeric matrix, it must have the same number of variables (columns) as was used to create mdl. Furthermore, all variables used in creating mdl must be numeric.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


Positive scalar from 0 to 1. Confidence level of yci is 100(1 – alpha)%.

Default: 0.05, meaning a 95% confidence interval.


String specifying the type of prediction:

  • 'curve'predict predicts confidence bounds for the fitted mean values.

  • 'observation'predict predicts confidence bounds for the new observations. This results in wider bounds because the error in a new observation is equal to the error in the estimated mean value, plus the variability in the observation from the true mean.

For details, see polyconf.

Default: 'curve'


Logical value specifying whether the confidence bounds are for all predictor values simultaneously (true), or hold for each individual predictor value (false). Simultaneous bounds are wider than separate bounds, because it is more stringent to require that the entire curve be within the bounds than to require that the curve at a single predictor value be within the bounds.

For details, see polyconf.

Default: false

Output Arguments


Vector of predicted mean values at Xnew.


Confidence intervals, a two-column matrix with each row providing one interval. The meaning of the confidence interval depends on the settings of the name-value pairs.


expand all

Predict Response to Data

Create a model of car mileage as a function of weight, and predict the response.

Create a quadratic model of car mileage as a function of weight from the carsmall data.

load carsmall
X = Weight;
y = MPG;
mdl = fitlm(X,y,'quadratic');

Create predicted responses to the data.

Xnew = X;
ypred = predict(mdl,Xnew);

Plot the original responses and the predicted responses to see how they differ.


Related Examples


feval gives the same predictions, but uses multiple input arrays with one component in each input argument. feval can be simpler to use with a model created from a table or dataset array tbl. feval does not give confidence intervals on its predictions.

random predicts with added noise.

Was this topic helpful?