General tabular regression
Predicting a continuous numeric target from tabular features.
Scikit-Learn · Class
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.
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.
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)| Name | Type | Description |
|---|---|---|
criterion | string, default='squared_error' | Split-quality measure: squared_error, absolute_error, or poisson. |
splitter | string, default='best' | Split-selection strategy: best or random. |
max_depth | int or None, default=None | Maximum tree depth; None expands until other stopping conditions apply. |
min_samples_split | int or float, default=2 | Minimum samples required to split an internal node; an integer count or fraction. |
min_samples_leaf | int or float, default=1 | Minimum samples required in a leaf; an integer count or fraction. |
min_weight_fraction_leaf | float, default=0.0 | Minimum weighted fraction of the total sample weight required in a leaf. |
max_features | int, float, {'sqrt', 'log2'} or None, default=None | Number of features considered when looking for a split. |
random_state | int, RandomState instance or None, default=None | Controls randomness used by the estimator. |
max_leaf_nodes | int or None, default=None | Maximum number of leaf nodes; None means unlimited. |
min_impurity_decrease | float, default=0.0 | Minimum weighted impurity decrease required for a split. |
ccp_alpha | non-negative float, default=0.0 | Complexity parameter used for Minimal Cost-Complexity Pruning. |
monotonic_cst | array-like of int or None, default=None | Monotonicity constraints for each feature, or None. |
A fitted DecisionTreeRegressor instance from fit; predict returns an array of predicted target values.
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.
Predicting a continuous numeric target from tabular features.
Modeling relationships that can be expressed through feature-threshold rules.
Producing predictions for several regression targets with one tree.
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.
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.
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.
DecisionTreeClassifierExtraTreeRegressorRandomForestRegressorHistGradientBoostingRegressorsklearn.tree.plot_tree