Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.


Clase: 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].

Argumentos de entrada

expandir todo

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

expandir todo

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.


expandir todo

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.