Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

DecisionTreeRegressor

DecisionTreeRegressor predicts continuous targets by recursively partitioning feature space with decision rules. Its criterion, split strategy, depth, leaf-size, and pruning parameters control how the tree is built and how complex it becomes.

How it works

The estimator recursively partitions feature space with decision rules chosen by the selected splitting criterion. Each terminal node predicts an aggregate of the training targets reaching it, such as a mean for squared error or a median for absolute error; depth and sample constraints control tree growth.

Syntax

class sklearn.tree.DecisionTreeRegressor(*, criterion='squared_error', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0, monotonic_cst=None)

Parameters

NameTypeDescription
criterionstring, default='squared_error'Split-quality measure: squared_error, absolute_error, or poisson.
splitterstring, default='best'Split-selection strategy: best or random.
max_depthint or None, default=NoneMaximum tree depth; None expands until other stopping conditions apply.
min_samples_splitint or float, default=2Minimum samples required to split an internal node; an integer count or fraction.
min_samples_leafint or float, default=1Minimum samples required in a leaf; an integer count or fraction.
min_weight_fraction_leaffloat, default=0.0Minimum weighted fraction of the total sample weight required in a leaf.
max_featuresint, float, {'sqrt', 'log2'} or None, default=NoneNumber of features considered when looking for a split.
random_stateint, RandomState instance or None, default=NoneControls randomness used by the estimator.
max_leaf_nodesint or None, default=NoneMaximum number of leaf nodes; None means unlimited.
min_impurity_decreasefloat, default=0.0Minimum weighted impurity decrease required for a split.
ccp_alphanon-negative float, default=0.0Complexity parameter used for Minimal Cost-Complexity Pruning.
monotonic_cstarray-like of int or None, default=NoneMonotonicity constraints for each feature, or None.

Returns

A fitted DecisionTreeRegressor instance from fit; predict returns an array of predicted target values.

Key points

  • DecisionTreeRegressor is the scikit-learn estimator for supervised regression with tree-based feature rules.
  • The default squared_error criterion uses mean-squared error and variance reduction to select splits.
  • absolute_error uses L1 loss and predicts with the median of each terminal node.
  • poisson selects splits by reducing Poisson deviance and uses the terminal-node mean.
  • splitter controls whether the best candidate split or a random candidate is selected.
  • max_depth caps the number of decision levels and is a primary control on model complexity.

Common mistakes

  • Leaving max_depth unset can allow the tree to grow until stopping conditions are reached, which may produce an overly complex model.
  • A depth that is too large can make the tree learn noise; use validation or cross-validation to choose complexity.
  • Do not use monotonic_cst with multi-output regression targets.

Example: Fit and predict with a regression tree

from sklearn.tree import DecisionTreeRegressor

X = [[0], [1], [2], [3]]
y = [0.0, 1.0, 4.0, 9.0]
model = DecisionTreeRegressor(max_depth=2, random_state=0)
model.fit(X, y)
print(model.predict([[1.5]]))

Fits a shallow regression tree to numeric training data and predicts a target for a new sample.

When to use it

General tabular regression

Predicting a continuous numeric target from tabular features.

Rule-based nonlinear prediction

Modeling relationships that can be expressed through feature-threshold rules.

Multi-output regression

Producing predictions for several regression targets with one tree.

Interview questions

QWhat does DecisionTreeRegressor learn?

It is a supervised, non-parametric regressor that learns simple feature-based decision rules and predicts a target value in each terminal region. For squared_error, the terminal-node prediction is based on the mean target.

Follow-up: How would you reduce overfitting? Restrict growth with max_depth, min_samples_leaf, max_leaf_nodes, or min_impurity_decrease, then evaluate the choice with cross-validation.

QHow does criterion affect training?

criterion selects the objective used to evaluate splits. The documented choices include squared_error, absolute_error, and poisson; the first uses variance reduction and mean terminal-node predictions, while absolute_error uses median terminal-node predictions.

Follow-up: When is absolute_error useful? It can be preferable when a median-based prediction and L1 loss better match the regression problem's error behavior.

QWhat is the purpose of min_samples_split?

min_samples_split sets the minimum number of samples needed to split an internal node. It accepts an integer count or a fraction; for a fraction, the threshold is computed by taking the ceiling of that fraction times the number of training samples.

Follow-up: How does min_samples_leaf differ? It constrains the minimum samples that must remain in each leaf, directly preventing very small terminal regions.

  • DecisionTreeClassifier
  • ExtraTreeRegressor
  • RandomForestRegressor
  • HistGradientBoostingRegressor
  • sklearn.tree.plot_tree

Source: DecisionTreeRegressor — scikit-learn 1.9.1 documentation. Checked 2026-10-15.