Main Content

feval

Evaluate nonlinear regression model prediction

Description

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

example

Examples

collapse all

Create a nonlinear model for auto mileage based on the carbig data. Predict the mileage of an average car.

Load the data and create a nonlinear model.

load carbig
tbl = table(Horsepower,Weight,MPG);
modelfun = @(b,x)b(1) + b(2)*x(:,1).^b(3) + ...
    b(4)*x(:,2).^b(5);
beta0 = [-50 500 -1 500 -1];
mdl = fitnlm(tbl,modelfun,beta0);

Find the predicted mileage of an average car. The data contains some missing (NaN) observations, so compute the mean using mean with the 'omitnan' option.

Xnew = mean([Horsepower Weight],'omitnan');
MPGnew = feval(mdl,Xnew)
MPGnew = 
21.8073

Input Arguments

collapse all

Nonlinear regression model object, specified as a NonLinearModel object created by using fitnlm.

New predictor values, specified as a vector, matrix, table, or dataset array.

  • If you pass multiple inputs Xnew1,Xnew2,...,Xnewn and each includes observations for one predictor variable, then each input must be a vector. Each vector must have the same size. If you specify a predictor variable as a scalar, then feval expands the scalar argument into a constant vector of the same size as the other arguments.

  • If you pass a single input Xnew1, then Xnew1 must be a table, dataset array, or matrix.

    • If Xnew1 is a table or dataset array, it must contain predictors that have the same predictor names as in the PredictorNames property of mdl.

    • If Xnew1 is a matrix, it must have the same number of variables (columns) in the same order as the predictor input used to create mdl. Note that Xnew1 must also contain any predictor variables that are not used as predictors in the fitted model. Also, all variables used in creating mdl must be numeric. To treat numerical predictors as categorical, identify the predictors using the 'CategoricalVars' name-value pair argument when you create mdl.

Data Types: single | double | table

Output Arguments

collapse all

Predicted response values at Xnew1,Xnew2,...,Xnewn, returned as a numeric vector.

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.

Version History

Introduced in R2012a