Main Content

Predict labels using classification tree

uses
additional options specified by one or more `label`

= predict(`Mdl`

,`X`

,`Name,Value`

)`Name,Value`

pair
arguments. For example, you can specify to prune `Mdl`

to
a particular level before predicting labels.

`[`

uses any of the input argument
in the previous syntaxes and additionally returns:`label`

,`score`

,`node`

,`cnum`

]
= predict(___)

A matrix of classification scores (

`score`

) indicating the likelihood that a label comes from a particular class. For classification trees, scores are posterior probabilities. For each observation in`X`

, the predicted class label corresponds to the minimum expected misclassification cost among all classes.A vector of predicted node numbers for the classification (

`node`

).A vector of predicted class number for the classification (

`cnum`

).

`predict`

generates predictions by following
the branches of `Mdl`

until it reaches a leaf node
or a missing value. If `predict`

reaches a leaf node,
it returns the classification of that node.

If `predict`

reaches a node with a missing value
for a predictor, its behavior depends on the setting of the `Surrogate`

name-value
pair when `fitctree`

constructs `Mdl`

.

(default) —`Surrogate`

=`'off'`

`predict`

returns the label with the largest number of training samples that reach the node.—`Surrogate`

=`'on'`

`predict`

uses the best surrogate split at the node. If all surrogate split variables with positive*predictive measure of association*are missing,`predict`

returns the label with the largest number of training samples that reach the node. For a definition, see Predictive Measure of Association.

To integrate the prediction of a classification tree model into Simulink^{®}, you can use the ClassificationTree
Predict block in the Statistics and Machine Learning Toolbox™ library or a MATLAB^{®} Function block with the `predict`

function. For
examples, see Predict Class Labels Using ClassificationTree Predict Block and Predict Class Labels Using MATLAB Function Block.

When deciding which approach to use, consider the following:

If you use the Statistics and Machine Learning Toolbox library block, you can use the

**Fixed-Point Tool (Fixed-Point Designer)**to convert a floating-point model to fixed point.Support for variable-size arrays must be enabled for a MATLAB Function block with the

`predict`

function.If you use a MATLAB Function block, you can use MATLAB functions for preprocessing or post-processing before or after predictions in the same MATLAB Function block.

`ClassificationTree`

| `compact`

| `CompactClassificationTree`

| `edge`

| `fitctree`

| `loss`

| `margin`

| `prune`