WOLFRAM

Enable JavaScript to interact with content and submit forms on Wolfram websites. Learn how
Wolfram Language & System Documentation Center

DecisionTreeModel []

represents an untrained decision tree.

DecisionTreeModel [hpars]

uses the custom hyperparameters hpars.

DecisionTreeModel [hpars,vars]

use the provided variables vars.

Details
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Hyperparameters  
"MaxDepth"  
"MinGain"  
"MinLeafSamples"  
"MinSamples"  
Variables  
Evaluation  
Information  
Fitting  
Applications  
Basic Uses  
Data Modeling  
Possible Issues  
Interactive Examples  
See Also
Related Guides
History
Cite this Page

DecisionTreeModel []

represents an untrained decision tree.

DecisionTreeModel [hpars]

uses the custom hyperparameters hpars.

DecisionTreeModel [hpars,vars]

use the provided variables vars.

Details

  • DecisionTreeModel models a classification or regression task as a sequence of binary choices based on a single input feature.
  • Decision trees are typically used with mixed-type data (categorical and numerical) to model nonlinear relationships and multiclass problems.
  • In a decision tree, each internal node represents a test and each leaf a final value.
  • Decision tree predictions are, in general, not continuous.
  • Hyperparameters
  • The following hyperparameters may be specified to control the decision tree:
  • "MaxDepth" 10 maximum number of splits per branch
    "MinGain" Scaled [0.01] minimal gain to keep a split
    "MinLeafSamples" 1 minimal number of samples per leaf node
    "MinSamples" 5 minimal number of samples to consider a split
  • Splits are evaluated by the model loss: the root mean square error for regression and the Gini index for classification.
  • "MaxDepth" controls model complexity: large values yield deeper trees prone to overfitting; small values yield shallower trees that may underfit.
  • A split is kept only if it reduces the loss by at least "MinGain". With "MinGain" Scaled [f], the threshold is f times the loss of the node being split rather than an absolute value.
  • "MinSamples" is the minimum sample count required for a node to be considered for splitting; "MinLeafSamples" is the minimum each resulting child must contain for a split to be accepted.
    Lower values produce finer splits at the cost of more noise.
  • Variables
  • When not specified, variables will automatically be enumerated using x [i].
  • Valid variable specifications vars include:
  • n the number of variables
    symb a symbolic representation of a single variable
    {symb1,} a list of symbolic variables
  • Properties
  • Model properties can be extracted using Information [PowerModel[],prop].
  • Valid basic properties include:
  • "BaseType" model base type
    "Name" model name
    "ShortName" short identifier to use as label
    "InputType" supported input types
    "OutputType" supported output types
  • Valid data-related properties include:
  • "ColumnNames" names of the input features
    "ColumnVariableMap" map between column names and model variables
    "InputSize" dimensionality of the input
    "OutputSize" dimensionality of the output
    "Trainable" whether the model is fully specified and can be trained
    "Trained" whether the model can be evaluated numerically
    "VariableColumnMap" map between model variables and column names
    "Variables" name of the model variables
  • Best model-related properties include:
  • "Expression" model expression
    "Function" model as a pure function
    "SymbolicExpression" model expression with symbolic parameters
    "TabularFunction" pure function suitable to work on a tabular row
  • Parameter-related properties include:
  • "Parameters" parameter values if present; names otherwise
    "ParameterValues" parameter values
  • Hyperparameter-related properties include:
  • "HyperparameterDefaultDomain" default hyperparameter search domain
    "HyperparameterDomain" specified hyperparameter search domain
    "Hyperparameters" hyperparameter values

Examples

open all close all

Basic Examples  (3)

Create a generic decision tree model:

Wolfram Language code: DecisionTreeModel[]

Specify multiple custom hyperparameters:

Wolfram Language code: DecisionTreeModel[<|"MaxDepth" -> 20, "MinSamples" -> 7|>]

Train a decision tree classifier on the Fisher Iris dataset:

Wolfram Language code: model = ModelFit[ResourceData["Sample Tabular Data: Fisher Iris"] -> "Species", DecisionTreeModel[]]

Extract the tree:

Wolfram Language code: Information[model, "Tree"]

Scope  (22)

Hyperparameters  (8)

"MaxDepth"  (2)

Define a tree with default "MaxDepth" value:

Wolfram Language code: DecisionTreeModel[]

Specify a custom value:

Wolfram Language code: DecisionTreeModel["MaxDepth" -> 3]

The tree depth controls how many times the input space is subdivided:

Wolfram Language code: data = {...};
Wolfram Language code: modelDefault = ModelFit[data, DecisionTreeModel[]]
Wolfram Language code: Information[modelDefault, "Tree"]

Reduce "MaxDepth" to prevent overfitting:

Wolfram Language code: model = ModelFit[data, DecisionTreeModel["MaxDepth" -> 3]]
Wolfram Language code: Information[model, "Tree"]

Compare the fits:

Wolfram Language code: Plot[{modelDefault[x], model[x]}, {x, 0, 100}, PlotLabels -> {"Default", "MaxDepth" -> 3}, Exclusions -> None, PlotLayout -> "Row", Prolog -> Point[data]]

"MinGain"  (3)

Specify the minimal gain of a split:

Wolfram Language code: data = Sin[Range[100] / 10.]; model = ModelFit[data, DecisionTreeModel["MinGain" -> .1]]
Wolfram Language code: ListPlot[data, PlotFit -> model]

Use zero gain to avoid any gain-based regularization:

Wolfram Language code: data = Sin[Range[100] / 10.]; model = ModelFit[data, DecisionTreeModel["MinGain" -> 0]]
Wolfram Language code: ListPlot[data, PlotFit -> model]

Find the best value of "MinGain" through cross-validation:

Wolfram Language code: model = ModelFit[Sin[Range[100] / 10.], DecisionTreeModel["MinGain" -> 0. | 0.01 | .1 | .5]]
Wolfram Language code: Information[model, "Hyperparameters"]

"MinLeafSamples"  (2)

Specify the minimal number of examples on every tree leaf:

Wolfram Language code: ModelFit[{...}, DecisionTreeModel["MinLeafSamples" -> 20]]
Wolfram Language code: Information[%, "Tree"]

Allow nodes to have a single example:

Wolfram Language code: ModelFit[{...}, DecisionTreeModel["MinLeafSamples" -> 1]]
Wolfram Language code: Information[%, "Tree"]

"MinSamples"  (1)

Specify the minimal number of example required to split a node:

Wolfram Language code: data = {...};
Wolfram Language code: model10 = ModelFit[data, DecisionTreeModel["MinSamples" -> 10]]
Wolfram Language code: Information[model10, "Tree"]

Using lower values results in a bushier tree with more leaves and risks overfitting:

Wolfram Language code: model2 = ModelFit[data, DecisionTreeModel["MinSamples" -> 2]]
Wolfram Language code: Information[model2, "Tree"]

Compare the fits:

Wolfram Language code: PlotGrid[{{ListPlot[data, PlotFit -> model10], ListPlot[data, PlotFit -> model2]}}]

Variables  (3)

Define a tree with a specific number of variables:

Wolfram Language code: DecisionTreeModel[Automatic, 2]

Use explicit variable names:

Wolfram Language code: DecisionTreeModel[Automatic, {x, y, z}]

ModelFit will assume the number of variables is one less than the dimensionality of data points:

Wolfram Language code: ModelFit[{{1, 9, 55}, {1, 1, 7}, {1, 4, 25}, {8, 9, 118}, {8, 10, 124}, {8, 5, 94}}, DecisionTreeModel[]]

Evaluation  (4)

Evaluate a trained decision tree model numerically:

Wolfram Language code: ModelFit[{...}, DecisionTreeModel[]][{1, 2}]

Evaluate a trained decision tree model symbolically:

Wolfram Language code: ModelFit[{...}, DecisionTreeModel[]][{x, y}]

Evaluate decision tree model on a list of inputs:

Wolfram Language code: ModelFit[{...}, DecisionTreeModel[]][{{1.17841, 7.0408}, {7.8774, 3.20304}, {5.12858, 7.89375}}]

Untrained decision trees cannot be evaluated symbolically:

Wolfram Language code: DecisionTreeModel[2, 1][x]

Information  (5)

View general information about a model:

Wolfram Language code: Information[DecisionTreeModel[]]

Some information is only available when variables or parameters are fully specified:

Wolfram Language code: Information[DecisionTreeModel[Association["Hyperparameters" -> Association["MaxDepth" -> 10, "MinSamples" -> 5, "MinLeafSamples" -> 1, "MinGain" -> 0.01]], Association["ParameterValues" -> Association["Feature" -> 1, "Threshold" -> 4, "Gain" -> 1722.25, "Size" -> 6, "FeatureType" -> "Numerical", "Left" -> Association["Value" -> Around[29., 14.], "Size" -> 3], "Right" -> Association["Value" -> Around[112., 9.16515138991168], "Size" -> 3]]], Association["Variables" -> {x}]]]

Extract a single property:

Wolfram Language code: Information[DecisionTreeModel[Association["Hyperparameters" -> Association["MaxDepth" -> 10, "MinSamples" -> 5, "MinLeafSamples" -> 1, "MinGain" -> 0.01]], Association["ParameterValues" -> Association["Feature" -> 1, "Threshold" -> 4, "Gain" -> 1722.25, "Size" -> 6, "FeatureType" -> "Numerical", "Left" -> Association["Value" -> Around[29., 14.], "Size" -> 3], "Right" -> Association["Value" -> Around[112., 9.16515138991168], "Size" -> 3]]], Association["Variables" -> {x}]], "Variables"]

Retrieve multiple properties:

Wolfram Language code: Information[DecisionTreeModel[Association["Hyperparameters" -> Association["MaxDepth" -> 10, "MinSamples" -> 5, "MinLeafSamples" -> 1, "MinGain" -> 0.01]], Association["ParameterValues" -> Association["Feature" -> 1, "Threshold" -> 4, "Gain" -> 1722.25, "Size" -> 6, "FeatureType" -> "Numerical", "Left" -> Association["Value" -> Around[29., 14.], "Size" -> 3], "Right" -> Association["Value" -> Around[112., 9.16515138991168], "Size" -> 3]]], Association["Variables" -> {x}]], {"Variables", "Hyperparameters"}]

Get information about the default model values:

Wolfram Language code: Information[DecisionTreeModel[Automatic, 2], {"Variables", "Hyperparameters"}]

Fitting  (2)

Fit a decision tree model with the default hyperparameters:

Wolfram Language code: ModelFit[{...}, DecisionTreeModel[]]

Fit multiple models at once:

Wolfram Language code: report = ModelFit[{...}, DecisionTreeModel["MaxDepth" -> 0 ;; 5], "Report"]

Compare the choice of hyperparameter values via cross-validation:

Wolfram Language code: report["CrossValidationChart"]

Applications  (4)

Basic Uses  (1)

Predict if a beaver is awake based on body temperature and time:

Wolfram Language code: ModelFit[ResourceData["Sample Data: Beaver Body Temperatures", "Dataset"] -> {"Temperature", "Active"}, DecisionTreeModel[Automatic, bodyTemperature], "Tree"]

Data Modeling  (3)

Retrieve data on the survival of passengers on the Titanic:

Wolfram Language code: titanicData = ResourceData["Sample Tabular Data: Titanic"]

Use a highly regularized decision tree model to understand the best predictors of survival:

Wolfram Language code: model = ModelFit[titanicData, DecisionTreeModel[<|"MinGain" -> .1|>]]

View the decision tree:

Wolfram Language code: Information[model, "Tree"]

Retrieve data that falls into multiple distinct distributions:

Wolfram Language code: data = ResourceData["Sample Data: Old Faithful Eruptions"];
Wolfram Language code: ListPlot[data]

Use a decision tree to predict the most likely duration based on the waiting time:

Wolfram Language code: model = ModelFit[data -> "WaitingTime", DecisionTreeModel[]]
Wolfram Language code: Show[ ListPlot[data], Plot[model[x], {x, Quantity[1, "Minutes"], Quantity[5, "Minutes"]}] ]

Increase the value of "MinLeafSamples" to avoid overfitting the noise within each section:

Wolfram Language code: modelRegularized = ModelFit[data -> "WaitingTime", DecisionTreeModel[<|"MinLeafSamples" -> 30|>]]
Wolfram Language code: Show[ ListPlot[data], Plot[modelRegularized[x], {x, Quantity[1, "Minutes"], Quantity[5, "Minutes"]}] ]

Retrieve data from the Fisher Iris dataset:

Wolfram Language code: data = ResourceData["Sample Tabular Data: Fisher Iris"]

Use a decision tree to classify the species according sepal and petal dimensions:

Wolfram Language code: model = ModelFit[data -> "Species", DecisionTreeModel[]]

Retrieve the features used:

Wolfram Language code: Union@Cases[Information[model, "TabularFunction"], Slot[name_] :> name, All]

Only the "PetalLength" and "PetalWidth" are used as predictors. Plot the data in that space:

Wolfram Language code: petalData = GroupBy[data, #"Species"&, KeyTake[{"PetalWidth", "PetalLength"}]];
Wolfram Language code: ListPlot[Normal /@ petalData, AxesLabel -> {"Width", "Length"}]

Compute the model prediction on a grid in the petal space:

Wolfram Language code: predictions = Table[model[<|"PetalWidth" -> Quantity[w, "Centimeters"], "PetalLength" -> Quantity[l, "Centimeters"], "SepalWidth" -> Quantity[1, "Centimeters"], "SepalLength" -> Quantity[1, "Centimeters"]|>], {w, 0, 2.5, .1}, {l, 0, 7, .2}];

Pick a color scheme for the classes:

Wolfram Language code: colors = {"setosa" -> Opacity[0.2, RGBColor[0.4, 0.6, 1]], "versicolor" -> Opacity[0.2, RGBColor[0.98, 0.56, 0.17]], "virginica" -> Opacity[0.2, RGBColor[0.14, 0.8, 0.14]]};

Visualize how the model segregates the space by species:

Wolfram Language code: regions = ArrayPlot[Replace[predictions, colors, {2}], ...]

Compare the data to the domain mapped out by the DecisionTreeModel :

Wolfram Language code: Show[ListPlot[Normal /@ petalData], regions, {...}]

Possible Issues  (2)

Specify a default model:

Wolfram Language code: DecisionTreeModel[]

DecisionTreeModel cannot be evaluated without fitting:

Wolfram Language code: DecisionTreeModel[][{Quantity[3, "Minutes"]}]

Fit the model to evaluate normally:

Wolfram Language code: model = ModelFit[ResourceData["Sample Data: Old Faithful Eruptions"], DecisionTreeModel[]]; model[{Quantity[3, "Minutes"]}]

DecisionTreeModel can be prone to overfitting on noisy datasets:

Wolfram Language code: data = ResourceData["Sample Data: Old Faithful Eruptions"]; model = ModelFit[data, DecisionTreeModel[]] Show[ ListPlot[data, PlotStyle -> StandardGray], Plot[model[x], {x, Quantity[1, "Minutes"], Quantity[6, "Minutes"]}] ]

Hyperparameters give a variety of methods to control how the tree splits the data and reduce overfitting:

Wolfram Language code: spec = {"MaxDepth" -> 2, "MinGain" -> 2, "MinSamples" -> 100, "MinLeafSamples" -> 20};

Fit a model for each specification:

Wolfram Language code: models = ModelFit[ data, DecisionTreeModel[#]]& /@ spec;

Visualize the fits alongside the original data:

Wolfram Language code: PlotGrid[Partition[MapThread[Show[ ListPlot[data, PlotStyle -> { StandardGray, Opacity[0.5]}], Plot[#[x], {x, Quantity[1, "Minutes"], Quantity[6, "Minutes"]}], PlotLabel -> #2 ]&, {models, spec}], 2], ImageSize -> Medium]

Interactive Examples  (1)

Compare the effect of the tree hyperparameters:

Wolfram Language code: Manipulate[Module[{model, data}, data = BlockRandom[Sin[Range[1000] / 100.] + RandomReal[{-.1, .1}, 1000]];model = N@ModelFit[data, DecisionTreeModel[<|"MaxDepth" -> depth, "MinSamples" -> samples, "MinGain" -> gain, "MinLeafSamples" -> leafsamples|>], "Function"]; ListPlot[{data, model /@ Range[1000.]}, Joined -> {False, True}, InterpolationOrder -> 0, PlotStyle -> {Opacity[.5], Thickness[0.01]}, ImageSize -> Medium] ], {{depth, 3}, 0, 10, 1}, {{samples, 10}, 1, 20, 1}, {{leafsamples, 5}, 1, 20, 1}, {gain, 0, .15}]

See Also

NearestModel   ModelFit   Classify   Predict   Tree

Methods: DecisionTree

Wolfram Research (2026), DecisionTreeModel, Wolfram Language function, https://reference.wolfram.com/language/ref/DecisionTreeModel.html.

Text

Wolfram Research (2026), DecisionTreeModel, Wolfram Language function, https://reference.wolfram.com/language/ref/DecisionTreeModel.html.

CMS

Wolfram Language. 2026. "DecisionTreeModel." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/DecisionTreeModel.html.

APA

Wolfram Language. (2026). DecisionTreeModel. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DecisionTreeModel.html

BibTeX

@misc{reference.wolfram_2026_decisiontreemodel, author="Wolfram Research", title="{DecisionTreeModel}", year="2026", howpublished="\url{https://reference.wolfram.com/language/ref/DecisionTreeModel.html}", note=[Accessed: 14-August-2026]}

BibLaTeX

@online{reference.wolfram_2026_decisiontreemodel, organization={Wolfram Research}, title={DecisionTreeModel}, year={2026}, url={https://reference.wolfram.com/language/ref/DecisionTreeModel.html}, note=[Accessed: 14-August-2026]}

Top [フレーム]

AltStyle によって変換されたページ (->オリジナル) /