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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
mdl | Any | Yes | — | Supported fitted model object, such as LinearModel from fitlm, ClassificationTree from fitctree, or ClassificationLinear from fitclinear. |
Xnew | Any | Yes | — | New predictor table or matrix. |
options | Any | Variadic | — | Prediction name-value options such as Alpha, Prediction, and Simultaneous. |
Returns
| Name | Type | Description |
|---|---|---|
ypred | NumericArray | Predicted response values. |
yci | NumericArray | Pointwise confidence intervals for the predicted response. |
label | Any | Predicted class labels. |
score | NumericArray | Posterior probabilities for each class. |
node | NumericArray | One-based terminal node index for each prediction. |
cnum | NumericArray | One-based class number for each predicted label. |
score | NumericArray | Classification scores or posterior probabilities. |
Returned values from predict depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:predict:InvalidArgument | The model, predictor data, or prediction options are malformed or unsupported. | predict: invalid argument |
RunMat:predict:Internal | RunMat cannot construct prediction outputs. | predict: internal error |
How predict works
Xnewcan be a numeric matrix with the same predictor column count used during fitting.- For table input, predictor variables are selected by the model's
PredictorNamesproperty. - 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, andDAGNetworkcompatibility objects,predict(net,Xnew)returns the score/activation matrix for the supported sequential feed-forward layer subset also used byforward. - Deep Learning prediction accepts
ObservationsInwithrowsorcolumns; column-observation input is transposed before execution. - Linear-model name-value options
Alpha,Prediction, andSimultaneousare accepted.Predictioncan becurveorobservation;Simultaneousmust 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.
Related Stats functions
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitctree · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · regress · ridge · squareform · test · training · tsne
Summary
binocdf · boxplot · cdf · cdfplot · chi2cdf · corr · corrcoef · corrcov · cov · cov2corr · dummyvar · ecdf · filloutliers · fitdist · geomean · grpstats · harmmean · icdf · isoutlier · kstest · kurtosis · lsline · mad · mode · nanmax · normalize · normcdf · norminv · normpdf · onehotdecode · onehotencode · pdf · prctile · quantile · refline · rmse · skewness · tabulate · tcdf · tiedrank · tinv · tpdf · ttest2 · wblinv
Random
binornd · bootstrp · datasample · dividerand · exprnd · gamrnd · lhsdesign · mvnrnd · normrnd · random · randsample · rng · trnd · unidrnd · unifrnd · wblrnd
Hist
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. 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 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.