mojolearn.ExtraTreesRegressor#
- class mojolearn.ExtraTreesRegressor(n_estimators=100, *, criterion='squared_error', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=1.0, max_leaf_nodes=None, min_impurity_decrease=0.0, bootstrap=False, oob_score=False, n_jobs=None, random_state=None, verbose=0, warm_start=False, ccp_alpha=0.0, max_samples=None, monotonic_cst=None, device='gpu', inference_engine='auto', numeric_mode=None)#
Extra-trees regressor with scikit-learn’s defaults.
Extremely randomized trees: each split draws one random threshold per candidate feature (scikit-learn’s random splitter, Geurts, Ernst and Wehenkel 2006) instead of searching for the best one. Defaults are scikit-learn’s, name for name. Every scikit-learn parameter is either honoured or refused by name; none is accepted and ignored.
Xis converted to float32; NaN or infinity inXraisesValueError.yis converted to float32. Leaf values are means of fixed-point quantized labels. Supports thefast(Apple GPUs only) andidenticalnumeric modes throughnumeric_mode.- Parameters:
n_estimators (int, default 100) – Number of trees.
criterion ({‘squared_error’, ‘poisson’, ‘gamma’, ‘inverse_gaussian’}, default ‘squared_error’) – Split criterion. ‘poisson’ requires finite
y >= 0with at least one positive value; ‘gamma’ and ‘inverse_gaussian’ require finitey > 0; otherwisefitraisesValueError. ‘absolute_error’ and ‘friedman_mse’ raiseNotImplementedError.max_depth (int or None, default None) – Maximum tree depth; None means unlimited.
min_samples_split (int, default 2) – Minimum rows needed to split a node.
min_samples_leaf (int, default 1) – Minimum rows in a leaf.
min_weight_fraction_leaf (float, default 0.0) – Only 0.0 is accepted; sample weights are not supported.
max_features ({‘sqrt’, ‘log2’}, int, float or None, default 1.0) – Features drawn per split: a name, a count, a fraction, or None for all features.
max_leaf_nodes (int or None, default None) – scikit-learn’s best-first growth: an int grows each tree to exactly that many leaves, expanding the node with the largest impurity improvement first (ties go to the smaller node id). None keeps depth-wise growth. The improvement is computed in float32.
min_impurity_decrease (float, default 0.0) – Minimum impurity decrease required to split.
bootstrap (bool, default False) – Sample rows with replacement for each tree.
oob_score (bool, default False) – Only False is accepted; out-of-bag scoring is not implemented.
n_jobs (None, default None) – Only None is accepted; any other value raises
NotImplementedError.random_state (int or None, default None) – Seed. None means seed 0, so the default fit is deterministic, unlike scikit-learn.
verbose (int, default 0) – Only 0 is accepted; any other value raises
NotImplementedError.warm_start (bool, default False) – Only False is accepted; there is no incremental fit.
ccp_alpha (float, default 0.0) – Only 0.0 is accepted; cost-complexity pruning is not implemented.
max_samples (int, float or None, default None) – Rows drawn per tree when
bootstrap=True, resolved as in scikit-learn: None means all rows, an int is a count, a float f means max(int(f * n_samples), 1). Setting it without bootstrap raises an error, as in scikit-learn.monotonic_cst (None, default None) – Only None is accepted.
device ({‘gpu’}, default ‘gpu’) – Only ‘gpu’ is accepted; other values raise
ValueError. On a CPU-only install the same calls run the host build of the trainer.inference_engine ({‘auto’, ‘sequential’, ‘parallel_groves’}, default ‘auto’) – How
predictreduces over trees. ‘auto’ uses ‘parallel_groves’ infastmode and ‘sequential’ otherwise.numeric_mode ({‘fast’, ‘identical’} or None, default None) – Numeric mode for this estimator; None uses the package default.
'fast'is available on Apple GPUs only.
- Variables:
n_features_in_ (int) – Number of features seen in
fit.
Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> X = rng.random((1000, 8), dtype=np.float32) >>> y = X[:, 0] * 2.0 + X[:, 1] >>> model = mojolearn.ExtraTreesRegressor(n_estimators=50).fit(X, y) >>> pred = model.predict(X)
See also
ExtraTreesClassifier,RandomForestRegressor,GradientBoostingRegressor,DecisionTreeRegressorUser guide: Trees and gradient boosting
Methods
apply(X)Return tree-relative leaf IDs, shape (rows, trees), from the native walk.
fit(X, y)Fit the forest.
get_params([deep])load(path)Load a forest saved by
save.The numeric mode this estimator runs in.
predict(X)Predicted values: the mean of the trees' predictions.
Return ordered raw mean scores (rows, outputs) and leaf IDs (rows, trees).
save(path)Write the fitted forest to
pathas an npz file.score(X, y[, sample_weight])Mode-aware GPU accuracy or Float32 R², weighted when
sample_weightis given (scikit-learn's weighted accuracy and R² on the pinned-sum path ofmetrics.accuracy_scoreandmetrics.r2_score).set_params(**params)Set constructor parameters.
Return eager mean prefixes, shape (rows, trees, outputs), in tree order.
The GPU backend this estimator runs on.
- fit(X, y)#
Fit the forest.
- Parameters:
X (array-like of shape (n_samples, n_features)) – Training data, converted to float32.
y (array-like of shape (n_samples,)) – Targets.
- Returns:
self
- predict(X)#
Predicted values: the mean of the trees’ predictions.
- Returns:
Array of shape (n_samples,), float64
- apply(X)#
Return tree-relative leaf IDs, shape (rows, trees), from the native walk.
- classmethod load(path)#
Load a forest saved by
save.The loaded model predicts; it does not refit. Loading a file saved by a different estimator class raises
ValueError.
- numeric_mode_used()#
The numeric mode this estimator runs in.
- Returns:
str –
'identical'or'fast', read from the compiled binary the estimator uses, not from the argument it was given.
- predict_with_leaves(X)#
Return ordered raw mean scores (rows, outputs) and leaf IDs (rows, trees).
Classifier scores are undecoded class votes. This auxiliary ordered contract is independent of an explicitly selected groves engine.
- save(path)#
Write the fitted forest to
pathas an npz file.The file holds the prediction arrays exactly as fitted, with exact dtypes; floats never pass through decimal text. A model saved with the ‘parallel_groves’ inference engine also records its engine and numeric mode. The file bytes depend only on the model, so equal models give equal file hashes on any machine.
- score(X, y, sample_weight=None)#
Mode-aware GPU accuracy or Float32 R², weighted when
sample_weightis given (scikit-learn’s weighted accuracy and R² on the pinned-sum path ofmetrics.accuracy_scoreandmetrics.r2_score).Class labels are compared without narrowing their values by the x_metrics binding’s grouped match count (
accuracy_fraction). Regression scoring uses the same Float32 target domain as tree fitting.
- set_params(**params)#
Set constructor parameters. The estimator is rebuilt through its constructor, so every constructor check runs again and any fitted state is dropped, as a new setting invalidates it.
- staged_predict(X)#
Return eager mean prefixes, shape (rows, trees, outputs), in tree order.
Each prefix uses the fixed increasing-tree fold through that tree. Only this requested API allocates the complete prefix buffer.
- vendor_used()#
The GPU backend this estimator runs on.
- Returns:
str –
'metal','cuda'or'hip', read from the compiled binary the estimator uses.