fitctree — Fit a binary decision tree for multiclass classification.

fitctree fits a numeric-predictor classification tree from a predictor matrix or table and returns a ClassificationTree object usable with predict.

Syntax

Mdl = fitctree(Tbl, ResponseVarName)
Mdl = fitctree(Tbl, formula)
Mdl = fitctree(X, Y)
Mdl = fitctree(___, Name, Value)

Inputs

NameTypeRequiredDefaultDescription
tblOrXAnyYesInput table or numeric predictor matrix.
yOrResponseAnyNoResponse vector, response variable name, or table formula.
optionsAnyVariadicName-value options such as ClassNames, PredictorNames, ResponseName, MaxNumSplits, MinLeafSize, MinParentSize, SplitCriterion, and Weights.

Returns

NameTypeDescription
MdlAnyClassificationTree object containing class names, split rules, and posterior probabilities.

Errors

IdentifierWhenMessage
RunMat:fitctree:InvalidArgumentInputs, response labels, dimensions, or name-value options are malformed or unsupported.fitctree: invalid argument
RunMat:fitctree:InternalRunMat cannot construct the ClassificationTree result.fitctree: internal error

How fitctree works

  • fitctree(X,Y) fits a classification tree with observations in rows of X and class labels in Y.
  • Table input supports fitctree(Tbl,ResponseVarName), fitctree(Tbl,formula), and fitctree(Tbl,Y). Formula support covers additive predictor lists such as Y ~ A + B.
  • Y can contain numeric, logical, string, char, or cell-string labels. The predicted label output preserves the label family.
  • Name-value options ClassNames, PredictorNames, ResponseName, MaxNumSplits, MinLeafSize, MinParentSize, SplitCriterion, Weights, and ScoreTransform are accepted.
  • SplitCriterion supports gdi and deviance. ScoreTransform currently accepts none.
  • Rows containing NaN in predictors, response, or zero weights are omitted before fitting; Inf values and negative weights are rejected.
  • Categorical predictors, pruning, surrogate splits, cross-validation, prior/cost matrices, and hyperparameter optimization are not implemented yet and raise explicit errors instead of silently producing partial models.
  • The returned object exposes ResponseName, PredictorNames, ClassNames, CategoricalPredictors, ScoreTransform, NumObservations, NumPredictors, NumNodes, NumSplits, and ModelParameters properties.

Examples

Fit and predict numeric classes

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

Expected output:

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

Fit a table-input classification tree

T = table(A, B, Y, 'VariableNames', {'A','B','Y'});
mdl = fitctree(T, 'Y ~ A + B')

Expected output:

mdl uses A and B as numeric predictors and Y as the response.

Using fitctree with coding agents

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

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

FAQ

Does fitctree support categorical predictors?

No. RunMat currently supports numeric predictors only and raises an explicit error for categorical-predictor options.

What does predict return for a classification tree?

predict(mdl,Xnew) returns predicted class labels. With multiple outputs, [label,score,node,cnum] returns posterior probabilities, one-based leaf node ids, and one-based class-number predictions.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how fitctree 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.