Skip to Content
OchreML
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, and score_buffer.
  • CPU Rayon & GPU N6 Path: Candidate split searches execute in parallel across CPU threads via Rust Rayon. On CUDA and wgpu devices (for datasets with at least 64 rows), continuous features can be quantized into u8 bins (max_bins=256) using the N6 histogram 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

ParameterTypeDefaultDescription
criterionstr"squared_error"Split quality criterion minimizing Mean Squared Error ("squared_error").
max_depthint | NoneNoneMaximum depth of the tree. If None, nodes expand until all leaves satisfy stopping criteria.
min_samples_splitint2Minimum number of samples required to split an internal node.
min_samples_leafint1Minimum number of samples required at a leaf node.
devicestr | NoneNoneTarget compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
n_features_in_int | NoneNumber of features seen during fit.
device_str | NoneResolved hardware device string used by the underlying Rust estimator.

Methods

MethodSignatureDescription
fitfit(X, y) -> DecisionTreeRegressorBuild a decision tree regressor from training set (X, y).
predictpredict(X) -> np.ndarrayPredict continuous target values for samples in X (falls back to Python list if NumPy is unavailable).
scorescore(X, y) -> floatReturn the coefficient of determination R^2 on test data (X, y).
savesave(path: str) -> NoneSerialize the fitted model to a binary .dit file.
loadDecisionTreeRegressor.load(path: str, device: str | None = None)Load a fitted regressor from a .dit file.
toto(device: str) -> DecisionTreeRegressorMove 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)

On this page