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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
tblOrX | Any | Yes | — | Input table or numeric predictor matrix. |
yOrResponse | Any | No | — | Response vector, response variable name, or table formula. |
options | Any | Variadic | — | Name-value options such as ClassNames, PredictorNames, ResponseName, MaxNumSplits, MinLeafSize, MinParentSize, SplitCriterion, and Weights. |
Returns
| Name | Type | Description |
|---|---|---|
Mdl | Any | ClassificationTree object containing class names, split rules, and posterior probabilities. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:fitctree:InvalidArgument | Inputs, response labels, dimensions, or name-value options are malformed or unsupported. | fitctree: invalid argument |
RunMat:fitctree:Internal | RunMat cannot construct the ClassificationTree result. | fitctree: internal error |
How fitctree works
fitctree(X,Y)fits a classification tree with observations in rows ofXand class labels inY.- Table input supports
fitctree(Tbl,ResponseVarName),fitctree(Tbl,formula), andfitctree(Tbl,Y). Formula support covers additive predictor lists such asY ~ A + B. Ycan 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, andScoreTransformare accepted. SplitCriterionsupportsgdianddeviance.ScoreTransformcurrently acceptsnone.- Rows containing
NaNin predictors, response, or zero weights are omitted before fitting;Infvalues 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, andModelParametersproperties.
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.
Related Stats functions
Ml
bayesopt · classify · confusionmat · crossvalind · cvpartition · fitclinear · fitlm · kmeans · knnsearch · lasso · lassoglm · linkage · lscov · mnrfit · optimizableVariable · pdist · pdist2 · perfcurve · predict · 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 fitctree is executed, line by line, in Rust.
- View the source for fitctree 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.