predict
Predict responses or class labels from a fitted model.
📝Syntax
yfit = predict(mdl, Xnew)
label = predict(mdl, Xnew)
[label, score] = predict(mdl, Xnew)
📥Input Arguments
Parameter Description
mdl a fitted model object, such as a LinearModel, GeneralizedLinearModel, or one of the regression or classification model objects returned by the fit functions.
Xnew numeric matrix of new observations: rows are observations and columns are predictors, matching the predictors used to train mdl.
📤Output Arguments
Parameter Description
yfit predicted response values for the observations in Xnew (regression models).
label predicted class labels for the observations in Xnew (classification models).
score classification scores for each observation and class (classification models that provide scores).
📄Description

predict is the common method used to evaluate a fitted model on new predictor data.

For regression models (for example the object returned by fitlm or fitglm), predict returns the predicted response yfit for each row of Xnew.

For classification models (for example the object returned by fitcsvm or fitctree), predict returns the predicted class label for each observation, and optionally a matrix of classification score values.

The columns of Xnew must correspond to the predictors used when the model was fitted.

💡Examples
Predict responses from a fitted linear model.
X = [1 2; 2 1; 3 4; 4 3];
y = [3; 3; 7; 7];
mdl = fitlm(X, y);
yfit = predict(mdl, [7 4; 8 5])
🔗See Also
fitlmfitglmfitcsvmfitctreeLinearModel
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub