Skip to Content
OchreML
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 with N6 histogram infrastructure on CUDA/wgpu and 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

ParameterTypeDefaultDescription
n_estimatorsint100Number of trees in the forest.
criterionstr"gini"Split quality criterion: "gini" or "entropy".
max_depthint | NoneNoneMaximum depth of each tree.
min_samples_splitint2Minimum number of samples required to split an internal node.
min_samples_leafint1Minimum number of samples required at a leaf node.
max_featuresstr | 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.
bootstrapboolFalseWhether bootstrap samples are used when building trees.
random_stateint | NoneNoneSeed controlling random threshold selection, feature sampling, and optional bootstrapping.
devicestr | NoneNoneTarget compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
classes_np.ndarray | NoneSorted 1D float64 array of unique class labels discovered during fit.
n_features_in_int | NoneNumber of features seen during fit.
feature_importances_np.ndarray | NoneNormalized impurity-based feature importances of shape (n_features,).
device_str | NoneResolved hardware device string used by the underlying Rust estimator.

Methods

MethodSignatureDescription
fitfit(X, y, sample_weight=None) -> ExtraTreesClassifierFit the Extra-Trees classifier on training data with optional sample weights.
predictpredict(X) -> np.ndarrayPredict class labels for samples in X.
predict_probapredict_proba(X) -> np.ndarrayPredict class probabilities of shape (n_samples, n_classes).
scorescore(X, y) -> floatReturn mean classification accuracy on (X, y).
savesave(path: str) -> NoneSave the fitted forest to a binary .dit file.
loadExtraTreesClassifier.load(path: str, device: str | None = None)Load a fitted classifier from a .dit file.
toto(device: str) -> ExtraTreesClassifierMove the estimator compute target to device.
set_deviceset_device(device: str | None = None) -> ExtraTreesClassifierSet 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]))

On this page