http://kr.mathworks.com/help/stats/compactlinearmodel.predict.html

 

predict

Class: CompactLinearModel

Predict response of linear regression model

Syntax

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

Description

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.

Tips

  • For predictions with added noise, use random.

Input Arguments

expand all

mdl — Linear model objectLinearModel object | CompactLinearModel object

Xnew — New predictor input valuestable | dataset array | numeric matrix

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.

'Alpha' — Alpha value for confidence interval0.05 (default) | numeric value in the range [0,1]

'Prediction' — Prediction type'curve' (default) | 'observation'

Examples

collapse all

Predict Response Values Using Linear Model

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.

plot(X,y,'o',Xnew,ypred,'x')
legend('Data','Predictions')

Related Examples

 

Posted by uniqueone
,