mojolearn.DecisionTreeRegressor#
- class mojolearn.DecisionTreeRegressor(*, criterion='squared_error', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0, monotonic_cst=None, n_bins=None, device='gpu', inference_engine='auto', numeric_mode=None)[source]#
Bases:
RandomForestRegressorA single regression tree (CART).
Follows scikit-learn’s
DecisionTreeRegressor: one tree grown on every row (no bootstrap) and, by default, every feature. Split thresholds are searched over per-feature quantile bins (cuML’s rule) rather than every midpoint, so thresholds can differ from scikit-learn’s.fitaccepts nosample_weight.Xandyare read as float32.- Parameters:
criterion ({“squared_error”, “mse”, “poisson”, “gamma”, “inverse_gaussian”}, default=”squared_error”) – Split quality measure.
"mse"is the same as"squared_error"."absolute_error"and"friedman_mse"raiseNotImplementedError.splitter ({“best”, “random”}, default=”best”) –
"best"searches the quantile bins of every candidate feature."random"grows one extremely randomized tree (one random threshold per candidate feature), the builder ofExtraTreesRegressor.max_depth (int or None, default=None) – Maximum depth of the tree. None grows until the other stopping rules apply.
min_samples_split (int, default=2) – Minimum number of rows a node needs before it can be split.
min_samples_leaf (int, default=1) – Minimum number of rows in each leaf.
min_weight_fraction_leaf (float, default=0.0) – Only 0.0 is accepted; any other value raises
NotImplementedError.max_features (int, float, {“sqrt”, “log2”} or None, default=None) – Number of features considered per split: an int count, a fraction in (0, 1],
"sqrt","log2", or None for every feature.random_state (int or None, default=None) – Seed for the random draws. None means seed 0, so repeated fits give the same tree (unlike scikit-learn, where None draws a fresh seed).
max_leaf_nodes (int or None, default=None) – Grow best-first to at most this many leaves. Supported only with
splitter="random"; withsplitter="best"it raisesNotImplementedError.min_impurity_decrease (float, default=0.0) – A node is split only if the split decreases impurity by at least this much.
ccp_alpha (float, default=0.0) – Only 0.0 is accepted; cost-complexity pruning is not implemented and any other value raises
NotImplementedError.monotonic_cst (None, default=None) – Only None is accepted; monotonic constraints raise
NotImplementedError.n_bins (int or None, default=None) – Number of quantile bins per feature used for the split search. None uses the numeric mode’s default: 128, or 256 in fast mode.
device ({“gpu”}, default=”gpu”) – Only
"gpu"is accepted. On a CPU-only install the same fit runs on the host binding.inference_engine ({“auto”, “sequential”, “parallel_groves”}, default=”auto”) – Prediction kernel.
"auto"lets the library choose; in identical mode it predicts as"sequential".numeric_mode ({“identical”, “deterministic”, “fast”} or None, default=None) – Numeric mode for this estimator. None uses the process default (see
mojolearn.set_numeric_mode)."fast"applies 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 @ rng.random(8, dtype=np.float32) >>> model = mojolearn.DecisionTreeRegressor(max_depth=6).fit(X, y) >>> pred = model.predict(X)
- __init__(*, criterion='squared_error', splitter='best', max_depth=None, min_samples_split=2, min_samples_leaf=1, min_weight_fraction_leaf=0.0, max_features=None, random_state=None, max_leaf_nodes=None, min_impurity_decrease=0.0, ccp_alpha=0.0, monotonic_cst=None, n_bins=None, device='gpu', inference_engine='auto', numeric_mode=None)[source]#
Methods
apply(X)Return tree-relative leaf IDs, shape (rows, trees), from the native walk.
fit(X, y[, sample_weight])Fit the tree.
Return the depth of the fitted tree.
Return the number of leaves of the fitted tree.
get_params([deep])load(path)Load a forest saved by
save.numeric_mode_used()The numeric mode this estimator runs in.
predict(X)Predict the target of each row of
X.predict_with_leaves(X)Return ordered raw mean scores (rows, outputs) and leaf IDs (rows, trees).
save(path)Save the fitted tree to
path.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.
staged_predict(X)Return eager mean prefixes, shape (rows, trees, outputs), in tree order.
vendor_used()The GPU backend this estimator runs on.