Trees, Ensembles & Boosting
DecisionTreeRegressor
CART regression tree minimizing Mean Squared Error backed by Rust Rayon and N6 GPU histogram acceleration.
DecisionTreeRegressor builds a binary Classification and Regression Tree (CART) for continuous targets by recursively partitioning the feature space to minimize Mean Squared Error (MSE). (o´∀`o)
Backend & Hardware Acceleration
- Zero-Copy Ingestion: Accepts NumPy arrays and Python Buffer Protocol objects directly via
fit_buffer,predict_buffer, andscore_buffer. - CPU Rayon & GPU
N6Path: Candidate split searches execute in parallel across CPU threads via Rust Rayon. On CUDA andwgpudevices (for datasets with at least 64 rows), continuous features can be quantized intou8bins (max_bins=256) using theN6histogram primitive for accelerated split evaluation. On TPU devices, tree building falls back cleanly to CPU Rayon.
Import & Signature
from ochreml.tree import DecisionTreeRegressor
# or: from ochreml import DecisionTreeRegressor
DecisionTreeRegressor(
criterion: str = "squared_error",
max_depth: Optional[int] = None,
min_samples_split: int = 2,
min_samples_leaf: int = 1,
device: Optional[str] = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
criterion | str | "squared_error" | Split quality criterion minimizing Mean Squared Error ("squared_error"). |
max_depth | int | None | None | Maximum depth of the tree. If None, nodes expand until all leaves satisfy stopping criteria. |
min_samples_split | int | 2 | Minimum number of samples required to split an internal node. |
min_samples_leaf | int | 1 | Minimum number of samples required at a leaf node. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
n_features_in_ | int | None | Number of features seen during fit. |
device_ | str | None | Resolved hardware device string used by the underlying Rust estimator. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y) -> DecisionTreeRegressor | Build a decision tree regressor from training set (X, y). |
predict | predict(X) -> np.ndarray | Predict continuous target values for samples in X (falls back to Python list if NumPy is unavailable). |
score | score(X, y) -> float | Return the coefficient of determination R^2 on test data (X, y). |
save | save(path: str) -> None | Serialize the fitted model to a binary .dit file. |
load | DecisionTreeRegressor.load(path: str, device: str | None = None) | Load a fitted regressor from a .dit file. |
to | to(device: str) -> DecisionTreeRegressor | Move the estimator to another target compute device. |
Example
import numpy as np
from ochreml.tree import DecisionTreeRegressor
X = np.array([[0.0], [1.0], [2.0], [3.0], [4.0], [5.0]], dtype=np.float64)
y = np.array([0.0, 1.0, 4.0, 9.0, 16.0, 25.0], dtype=np.float64)
reg = DecisionTreeRegressor(max_depth=3, device="auto")
reg.fit(X, y)
preds = reg.predict(np.array([[1.5], [3.5]], dtype=np.float64))
r2 = reg.score(X, y)
print("Predictions:", preds)
print("R^2 score:", r2)