yfit = predict(mdl, Xnew)
label = predict(mdl, Xnew)
[label, score] = predict(mdl, Xnew)
| 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. |
| 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). |
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.
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])
| Version | Description |
|---|---|
| 2.0.0 | initial version |