This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Class: CompactLinearModel

Evaluate linear regression model prediction


ypred = feval(mdl,Xnew1,Xnew2,...,Xnewn)


ypred = feval(mdl,Xnew1,Xnew2,...,Xnewn) returns the predicted response of mdl to the new input predictors [Xnew1,Xnew2,...,Xnewn].

Input Arguments

expand all

Linear model object, specified as a full LinearModel object constructed using fitlm or stepwiselm, or a compacted CompactLinearModel object constructed using compact.

New predictor values, specified as a scalar value, numeric vector, or numeric array. You can specify multiple components for this argument. Each vector component must have the same number of elements in each dimension (in other words, each vector must be same size).

If you pass just one Xnew array, then Xnew can be a table, dataset array, or an array of doubles, where each column of the array represents one predictor.

Output Arguments

expand all

Predicted mean values at Xnew1,Xnew2,...,Xnewn, returned as a scalar value or numeric vector. ypred is the same size as each component of Xnew1,Xnew2,...,Xnewn.

For models with an offset, feval uses 0 as the offset value.


expand all

Fit a mileage model to the carsmall data, including the Year categorical predictor. Superimpose fitted curves on a scatter plot of the data.

Load the data and fit a model.

load carsmall
tbl = table(MPG,Weight);
tbl.Year = ordinal(Model_Year);
mdl = fitlm(tbl,'MPG ~ Year + Weight^2');

Create a scatter plot of the mileage versus weight.


Use feval to plot curves of the model predictions for the various years and weights.

w = linspace(min(tbl.Weight),max(tbl.Weight))';


predict gives the same predictions, but uses a single input array with one observation in each row, rather than one component in each input argument. predict also gives confidence intervals on its predictions.

random predicts with added noise.