CART Decision Tree for classification and regression.
Classes
CART decision tree for classification.
__init__( self, criterion: str = 'gini', max_depth: Optional[int] = None, min_samples_split: int = 2, min_samples_leaf: int = 1, min_impurity_decrease: float = 0.0, ccp_alpha: float = 0.0, random_state: Optional[int] = None, )
Overview
- Build the tree recursively using the selected impurity criterion
- After fitting, flatten the tree into parallel arrays
- Predict via efficient tree traversal
Theory
Gini impurity (criterion="gini"):
Entropy / information gain (criterion="entropy" or "log_loss"):
Gain ratio (criterion="gain_ratio", C4.5):
where p_k is the proportion of class k in the node. A split is chosen to maximise the weighted impurity reduction (or gain ratio for C4.5):
Optional minimal cost-complexity pruning removes branches whose effective \alpha is below ccp_alpha.
Parameters
criterion
"gini" for the Gini impurity (CART), "entropy" for the information gain (ID3), "log_loss" (alias for entropy), and "gain_ratio" for the C4.5 gain-ratio criterion.
max_depth
None means unlimited.
min_samples_split
min_samples_leaf
min_impurity_decrease
ccp_alpha
ccp_alpha are pruned.
random_state
Attributes
tree_
flat_tree_
classes_
fit().
n_classes_
n_features_
fit().
max_depth_
n_nodes_
Notes
Complexity:
- Training: O(n \cdot m \cdot n \log n) where n = samples,
- Prediction: O(d) per sample where d = tree depth, fully
When to use DecisionTreeClassifier:
- Large datasets where JIT-compiled splitting provides speedups
- Batch prediction on GPU/TPU backends
- When you need an interpretable single-tree model with hardware acceleration
References
See Also
>>> from tuiml.algorithms.trees import DecisionTreeClassifier
>>> import numpy as np
>>>
>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8], [2, 3], [4, 5]])
>>> y = np.array([0, 0, 1, 1, 0, 1])
>>>
>>> clf = DecisionTreeClassifier(max_depth=3)
>>> clf.fit(X, y)
DecisionTreeClassifier(max_depth=3, n_nodes=...)
>>> predictions = clf.predict(X)
Methods
CART decision tree for regression.
__init__( self, criterion: str = 'squared_error', max_depth: Optional[int] = None, min_samples_split: int = 2, min_samples_leaf: int = 1, min_impurity_decrease: float = 0.0, ccp_alpha: float = 0.0, random_state: Optional[int] = None, )
Overview
- Build the tree recursively using the selected impurity criterion
- After fitting, flatten the tree into parallel arrays
- Predict via efficient tree traversal
Theory
Squared error (criterion="squared_error"):
Friedman MSE (criterion="friedman_mse"):
Absolute error (criterion="absolute_error"):
Each leaf stores the mean (squared error, Friedman MSE) or median (absolute error) of its training targets.
Parameters
criterion
"squared_error" for variance reduction (CART), "friedman_mse" for Friedman's improvement score (better for boosting), and "absolute_error" for mean absolute error using median predictions.
max_depth
None means unlimited.
min_samples_split
min_samples_leaf
min_impurity_decrease
ccp_alpha
random_state
Attributes
tree_
flat_tree_
n_features_
fit().
max_depth_
n_nodes_
Notes
Complexity:
- Training: O(n \cdot m \cdot n \log n) where n = samples,
- Prediction: O(d) per sample where d = tree depth, fully
When to use DecisionTreeRegressor:
- Large regression datasets where JIT-compiled criteria speed up training
- Batch prediction on GPU/TPU backends
- When you need an interpretable single-tree regression model with hardware
References
See Also
>>> from tuiml.algorithms.trees import DecisionTreeRegressor
>>> import numpy as np
>>>
>>> X = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
>>> y = np.array([1.0, 2.0, 3.0, 4.0])
>>>
>>> reg = DecisionTreeRegressor(max_depth=3)
>>> reg.fit(X, y)
DecisionTreeRegressor(max_depth=3, n_nodes=...)
>>> predictions = reg.predict(X)