predict — Predict responses from a fitted model.
predict(mdl,Xnew) evaluates supported fitted LinearModel, ClassificationTree, ClassificationLinear, and 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)
Y = predict(net, X)
[Y,state] = predict(dlnetwork, X)Inputs
mdl- Type
Any- Required
- Yes
- Description
- Supported fitted statistical model or deep-learning network object.
Xnew- Type
Any- Required
- Yes
- Description
- New predictor table, matrix, array, or dlarray.
options- Type
Any- Required
- Variadic
- Description
- Supported model-specific name-value options.
Returns
ypred- Type
NumericArray- Description
- Predicted response values.
yci- Type
NumericArray- Description
- Pointwise confidence intervals for the predicted response.
label- Type
Any- Description
- Predicted class labels.
score- Type
NumericArray- Description
- Classification scores or posterior probabilities.
node- Type
NumericArray- Description
- One-based terminal node index for each prediction.
cnum- Type
NumericArray- Description
- One-based class number for each predicted label.
Y- Type
Any- Description
- Predicted network scores in the selected output axis convention.
state- Type
Any- Description
- Updated dlnetwork state, when requested and supported.
Returned values from predict depend on how many outputs the caller requests.
Errors
RunMat:predict:InvalidArgument- When
- The model, predictor data, or prediction options are malformed or unsupported.
- Message
predict: invalid argument
RunMat:predict:Internal- When
- RunMat cannot construct prediction outputs.
- Message
predict: internal error
Statistical models
Xnew can be a numeric matrix with the predictor column count used during fitting. For table input, variables are selected by the model's PredictorNames property.
LinearModel returns predicted responses. [ypred,yci] = predict(...) returns pointwise confidence intervals for curve predictions by default. Alpha, Prediction, and Simultaneous options are accepted; Prediction is curve or observation, and Simultaneous must be false because simultaneous intervals are not yet supported.
ClassificationTree can return labels, posterior scores, one-based terminal node indices, and one-based class numbers. Tree prediction accepts matrix or table predictors and reports unsupported pruning or subtree options explicitly. ClassificationLinear can return labels and scores.
Typed-integer predictors and numeric controls for implemented statistical models are independently gated RunMat-mode extensions with checked double boundaries.
Implemented statistical predictors gather to host for model evaluation.
Deep-learning networks
Deep-learning prediction uses the same admitted sequential layer execution as forward. A formatted dlarray input returns a formatted dlarray in the output axis order; an unformatted dlarray returns an unformatted dlarray; raw numeric input returns a numeric score array.
For an unformatted dlarray, same-rank output retains the input axis order. If rank changes, batch precedes the remaining output axes. Raw numeric predictions use observation-major presentation.
ObservationsIn accepts rows or columns. A formatted dlarray with incompatible labels is rejected instead of relabeled; the input dlarray and differentiation provenance are preserved.
A dlnetwork can return updated State as a second output. Current SeriesNetwork and DAGNetwork compatibility routes return one output. Supported single- and double-precision resident GPU network inputs execute without gathering; unsupported explicit gpuArray routes return an error.
Supported deep-learning networks retain their documented integer-input contract, separate from the statistical-model integer extensions.
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
mdl = fitlm([0; 1; 2; 3], [1; 3; 5; 7]);
[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 from fitlm, ClassificationTree from fitctree, ClassificationLinear from fitclinear, and supported deep-learning network objects.
Related Stats functions
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · nlparci · optimizableVariable · pdist · pdist2 · perfcurve · regress · ridge · squareform · test · training · tsne
Summary
anova1 · binocdf · binscatter · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · ksdensity · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pca · pdf · prctile · qqplot · quantile · refline · rmse · scatterhist · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest · ttest2 · wblinv
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · gpurng · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Source you can read
Every RunMat function's source is public. Read exactly how predict is executed, line by line, in Rust.
- View the source for predict in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/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.