Trees, Ensembles & Boosting
ExtraTreesRegressor
Extremely randomized regression tree ensemble with random split thresholds, Rayon parallelism, and N6 GPU support.
ExtraTreesRegressor fits an ensemble of randomized regression trees that draw random split thresholds for candidate features and average leaf predictions across the forest to reduce variance. (o´∀`o)
Backend & Hardware Acceleration
- Parallel Forest Execution: Individual regression trees are trained concurrently with Rust Rayon across CPU cores.
- GPU
N6& CPU/TPU Fallback: Integrates with OchreML'sN6histogram path on CUDA/wgpuwhere applicable and falls back seamlessly to CPU Rayon on CPU and TPU targets. - Default
bootstrap=False: Uses the full training set for each tree by default (bootstrap=False) withmax_features=1.0, deriving ensemble diversity from randomized split thresholds.
Import & Signature
from ochreml.ensemble import ExtraTreesRegressor
# or: from ochreml import ExtraTreesRegressor
ExtraTreesRegressor(
n_estimators: int = 100,
criterion: str = "squared_error",
max_depth: Optional[int] = None,
min_samples_split: int = 2,
min_samples_leaf: int = 1,
max_features: Union[str, int, float, None] = 1.0,
bootstrap: bool = False,
random_state: Optional[int] = None,
device: Optional[str] = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
n_estimators | int | 100 | Number of regression trees in the forest. |
criterion | str | "squared_error" | Split quality criterion ("squared_error"). |
max_depth | int | None | None | Maximum depth of each tree. |
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. |
max_features | str | int | float | None | 1.0 | Number of features considered at each split: "sqrt", "log2", "all", positive int, fraction float in (0.0, 1.0], or None. |
bootstrap | bool | False | Whether bootstrap samples are used when building trees. |
random_state | int | None | None | Seed controlling random threshold selection, feature sampling, and optional bootstrapping. |
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. |
feature_importances_ | np.ndarray | None | Normalized impurity-based feature importances of shape (n_features,). |
device_ | str | None | Resolved hardware device string used by the underlying Rust estimator. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y, sample_weight=None) -> ExtraTreesRegressor | Fit the Extra-Trees regressor on training data with optional sample weights. |
predict | predict(X) -> np.ndarray | Predict continuous target values for samples in X. |
score | score(X, y) -> float | Return the coefficient of determination R^2 on (X, y). |
save | save(path: str) -> None | Save the fitted forest to a binary .dit file. |
load | ExtraTreesRegressor.load(path: str, device: str | None = None) | Load a fitted regressor from a .dit file. |
to | to(device: str) -> ExtraTreesRegressor | Move the estimator compute target to device. |
set_device | set_device(device: str | None = None) -> ExtraTreesRegressor | Set or reset the compute device for the estimator. |
Example
import numpy as np
from ochreml.ensemble import ExtraTreesRegressor
rng = np.random.default_rng(19)
X = rng.uniform(-2.0, 2.0, size=(100, 3))
y = 2.0 * X[:, 0] ** 2 - X[:, 1] + 0.5 * X[:, 2]
reg = ExtraTreesRegressor(
n_estimators=50,
max_depth=8,
random_state=19,
device="auto",
)
reg.fit(X, y)
print("R^2 score:", reg.score(X, y))
print("Feature importances:", reg.feature_importances_)
print("Sample predictions:", reg.predict(X[:4]))