predict — Predict responses from a fitted model.

predict(mdl,Xnew) evaluates supported fitted model objects, including LinearModel from fitlm, ClassificationTree from fitctree, and supported Deep Learning network objects, on new predictor data.

Syntax

ypred = predict(mdl, Xnew)
[ypred, yci] = predict(mdl, Xnew)
[ypred, yci] = predict(mdl, Xnew, Name, Value)
label = predict(tree, Xnew)
[label,score,node,cnum] = predict(tree, Xnew)
[label,score] = predict(linearClassifier, Xnew)

Inputs

NameTypeRequiredDefaultDescription
mdlAnyYesSupported fitted model object, such as LinearModel from fitlm, ClassificationTree from fitctree, or ClassificationLinear from fitclinear.
XnewAnyYesNew predictor table or matrix.
optionsAnyVariadicPrediction name-value options such as Alpha, Prediction, and Simultaneous.

Returns

NameTypeDescription
ypredNumericArrayPredicted response values.
yciNumericArrayPointwise confidence intervals for the predicted response.
labelAnyPredicted class labels.
scoreNumericArrayPosterior probabilities for each class.
nodeNumericArrayOne-based terminal node index for each prediction.
cnumNumericArrayOne-based class number for each predicted label.
scoreNumericArrayClassification scores or posterior probabilities.

Returned values from predict depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:predict:InvalidArgumentThe model, predictor data, or prediction options are malformed or unsupported.predict: invalid argument
RunMat:predict:InternalRunMat cannot construct prediction outputs.predict: internal error

How predict works

  • Xnew can be a numeric matrix with the same predictor column count used during fitting.
  • For table input, predictor variables are selected by the model's PredictorNames property.
  • For LinearModel, [ypred,yci] = predict(...) returns pointwise confidence intervals for curve predictions by default.
  • For ClassificationTree, [label,score,node,cnum] = predict(...) returns predicted class labels, posterior probabilities, one-based leaf node ids, and one-based class-number predictions.
  • For dlnetwork, SeriesNetwork, and DAGNetwork compatibility objects, predict(net,Xnew) returns the score/activation matrix for the supported sequential feed-forward layer subset also used by forward.
  • Deep Learning prediction accepts ObservationsIn with rows or columns; column-observation input is transposed before execution.
  • Linear-model name-value options Alpha, Prediction, and Simultaneous are accepted. Prediction can be curve or observation; Simultaneous must be false because simultaneous intervals are not supported yet.
  • Classification-tree prediction currently accepts matrix or table predictor data and raises explicit errors for unsupported pruning/subtree options.

Examples

Predict from a linear model

mdl = fitlm([0; 1; 2; 3], [1; 3; 5; 7]);
yhat = predict(mdl, [4; 5])

Expected output:

yhat is approximately [9; 11].

Return confidence intervals

[yhat, yci] = predict(mdl, [4; 5], 'Alpha', 0.01)

Expected output:

yci is a two-column matrix with lower and upper bounds.

Predict classes from a classification tree

tree = fitctree([0; 1; 2; 3], [0; 0; 1; 1], 'MaxNumSplits', 1, 'MinParentSize', 2);
[label,score] = predict(tree, [0.5; 2.5])

Expected output:

label is [0; 1], and score has one posterior-probability column per class.

Predict from a dlnetwork

layers = {featureInputLayer(2,'Name','in'); fullyConnectedLayer(2,'Name','fc'); softmaxLayer('Name','prob')};
net = dlnetwork(layers);
scores = predict(net, [1 2; 3 4])

Expected output:

scores has one row per observation.

Using predict with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how predict changes the result.

Run a small predict example, explain the result, then change one input and compare the output.

FAQ

Which model classes are supported?

Currently predict supports LinearModel objects returned by fitlm, ClassificationTree objects returned by fitctree, and supported Deep Learning network compatibility objects.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how predict is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.