Trees, Ensembles & Boosting
ExtraTreesClassifier
Extremely randomized decision tree classifier with random split thresholds, Rayon parallelism, and N6 GPU support.
ExtraTreesClassifier (Extremely Randomized Trees) fits an ensemble of randomized decision trees where split thresholds for each candidate feature are drawn at random rather than exhaustively searching for the optimal cut point, reducing variance and speeding up training. (o´∀`o)
Backend & Hardware Acceleration
- Parallel Tree Building: Trees are constructed concurrently via Rust Rayon with independent per-tree RNG streams seeded by
random_state. - GPU
N6& CPU/TPU Fallback: Shares OchreML's forest backend withN6histogram infrastructure on CUDA/wgpuand automatic Rayon CPU fallback on CPU and TPU targets. - Default
bootstrap=False: Following Scikit-Learn conventions, Extra-Trees uses the full dataset per tree by default (bootstrap=False), relying on random split thresholds and feature subsampling (max_features="sqrt") for diversity.
Import & Signature
from ochreml.ensemble import ExtraTreesClassifier
# or: from ochreml import ExtraTreesClassifier
ExtraTreesClassifier(
n_estimators: int = 100,
criterion: str = "gini",
max_depth: Optional[int] = None,
min_samples_split: int = 2,
min_samples_leaf: int = 1,
max_features: Union[str, int, float, None] = "sqrt",
bootstrap: bool = False,
random_state: Optional[int] = None,
device: Optional[str] = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
n_estimators | int | 100 | Number of trees in the forest. |
criterion | str | "gini" | Split quality criterion: "gini" or "entropy". |
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 | "sqrt" | 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 |
|---|---|---|
classes_ | np.ndarray | None | Sorted 1D float64 array of unique class labels discovered during fit. |
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) -> ExtraTreesClassifier | Fit the Extra-Trees classifier on training data with optional sample weights. |
predict | predict(X) -> np.ndarray | Predict class labels for samples in X. |
predict_proba | predict_proba(X) -> np.ndarray | Predict class probabilities of shape (n_samples, n_classes). |
score | score(X, y) -> float | Return mean classification accuracy on (X, y). |
save | save(path: str) -> None | Save the fitted forest to a binary .dit file. |
load | ExtraTreesClassifier.load(path: str, device: str | None = None) | Load a fitted classifier from a .dit file. |
to | to(device: str) -> ExtraTreesClassifier | Move the estimator compute target to device. |
set_device | set_device(device: str | None = None) -> ExtraTreesClassifier | Set or reset the compute device for the estimator. |
Example
import numpy as np
from ochreml.ensemble import ExtraTreesClassifier
rng = np.random.default_rng(123)
X0 = rng.normal(loc=[-1.0, -1.0], scale=0.7, size=(50, 2))
X1 = rng.normal(loc=[1.0, 1.0], scale=0.7, size=(50, 2))
X = np.vstack([X0, X1])
y = np.array([0.0] * 50 + [1.0] * 50)
clf = ExtraTreesClassifier(
n_estimators=60,
criterion="entropy",
max_depth=6,
random_state=123,
device="auto",
)
clf.fit(X, y)
print("Accuracy:", clf.score(X, y))
print("Predicted probabilities (first 3):\n", clf.predict_proba(X[:3]))