Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

feval

Class: CompactLinearModel

Evaluate linear regression model prediction

Syntax

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

Description

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.

Examples

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.

gscatter(tbl.Weight,tbl.MPG,tbl.Year);

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

w = linspace(min(tbl.Weight),max(tbl.Weight))';
line(w,feval(mdl,w,'70'),'Color','r')
line(w,feval(mdl,w,'76'),'Color','g')
line(w,feval(mdl,w,'82'),'Color','b')

Related Examples

Alternatives

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.

Was this topic helpful?