RandomForestClassifier#

class cuml.dask.ensemble.RandomForestClassifier(
*,
workers=None,
client=None,
verbose=False,
n_estimators=100,
random_state=None,
ignore_empty_partitions=None,
**kwargs,
)[source]#

Multi-GPU Random Forest classifier model which fits multiple decision tree classifiers in an ensemble. This uses Dask to partition data over multiple GPUs (possibly on different nodes).

During fitting, all workers that hold training rows collectively build the same forest from the complete distributed dataset.

Parameters:
n_estimatorsint (default = 100)

total number of trees in the forest

split_criterionint or string (default = 0 ('gini'))

The criterion used to split nodes.

  • 0 or 'gini' for gini impurity

  • 1 or 'entropy' for information gain (entropy)

  • 2 or 'mse' for mean squared error

  • 4 or 'poisson' for poisson half deviance

  • 5 or 'gamma' for gamma half deviance

  • 6 or 'inverse_gaussian' for inverse gaussian deviance

2, 'mse', 4, 'poisson', 5, 'gamma', 6, 'inverse_gaussian' not valid for classification

bootstrapboolean (default = True)

Control bootstrapping.

  • If True, each tree in the forest is built on a bootstrapped sample with replacement.

  • If False, the whole dataset is used to build each tree.

Weighted bootstrapping through sample_weight or class_weight is not yet supported for distributed random forests.

max_samplesfloat (default = 1.0)

Ratio of dataset rows used while fitting each tree.

max_depthint or None (default = None)

Maximum tree depth. Use None for unlimited depth (trees grow until all leaves are pure). Must be a positive integer or None.

Changed in version 26.08: The default of max_depth changed from 16 to None.

max_leavesint (default = -1)

Maximum leaf nodes per tree. Soft constraint. Unlimited, If -1.

max_featuresfloat (default = ‘auto’)

Ratio of number of features (columns) to consider per node split.

  • If type int then max_features is the absolute count of features to be used.

  • If type float then max_features is a fraction.

  • If 'auto' then max_features=n_features = 1.0.

  • If 'sqrt' then max_features=1/sqrt(n_features).

  • If 'log2' then max_features=log2(n_features)/n_features.

  • If None, then max_features = 1.0.

n_binsint (default = 128)

Maximum number of bins used by the split algorithm per feature.

min_samples_leafint or float (default = 1)

The minimum number of samples (rows) in each leaf node.

  • If type int, then min_samples_leaf represents the minimum number.

  • If float, then min_samples_leaf represents a fraction and ceil(min_samples_leaf * n_rows) is the minimum number of samples for each leaf node.

min_samples_splitint or float (default = 2)

The minimum number of samples required to split an internal node.

  • If type int, then min_samples_split represents the minimum number.

  • If type float, then min_samples_split represents a fraction and ceil(min_samples_split * n_rows) is the minimum number of samples for each split.

n_streamsint

Deprecated. Distributed training currently builds trees serially to preserve collective order.

workersoptional, list of strings

Dask addresses of workers to use for computation. If None, all available Dask workers will be used.

random_stateint (default = None)

Seed for the random number generator. Unseeded by default.

ignore_empty_partitions: optional, boolean

Deprecated. This parameter no longer has any effect and will be removed in release 26.12.

Attributes:
oob_decision_function_

Methods

fit(X, y[, broadcast_data, sample_weight])

Fit the input data with a Random Forest classifier

get_params([deep])

Returns the value of all parameters required to configure this estimator as a dictionary.

predict(X[, threshold, layout, ...])

Predicts the labels for X.

predict_proba(X[, delayed])

Predicts the probability of each class for X.

set_params(**params)

Sets the value of parameters required to configure this estimator, it functions similar to the sklearn set_params.

fit(
X,
y,
broadcast_data=None,
sample_weight=None,
)[source]#

Fit the input data with a Random Forest classifier

Only workers holding one or more training rows participate in fitting.

If a worker has multiple data partitions, they will be concatenated before fitting, which will lead to additional memory usage. To minimize memory consumption, ensure that each worker has exactly one partition.

When persisting data, you can use cuml.dask.common.utils.persist_across_workers to simplify this:

X_dask_cudf = dask_cudf.from_cudf(X_cudf, npartitions=n_workers)
y_dask_cudf = dask_cudf.from_cudf(y_cudf, npartitions=n_workers)
X_dask_cudf, y_dask_cudf = persist_across_workers(dask_client,
                                                  [X_dask_cudf,
                                                   y_dask_cudf])

This is equivalent to calling persist with the data and workers:

X_dask_cudf, y_dask_cudf = dask_client.persist([X_dask_cudf,
                                                y_dask_cudf],
                                               workers={
                                               X_dask_cudf:workers,
                                               y_dask_cudf:workers
                                               })
Parameters:
XDask cuDF dataframe or CuPy backed Dask Array (n_rows, n_features)

Distributed dense matrix (floats or doubles) of shape (n_samples, n_features).

yDask cuDF dataframe or CuPy backed Dask Array (n_rows, 1)

Labels of training examples. y must be partitioned the same way as X

sample_weightarray-like, optional

Sample weights are not yet supported by distributed random forests.

broadcast_databool, optional

Deprecated. This parameter no longer has effect and will be removed in release 26.12.

get_combined_model()[source]#

Return single-GPU model for serialization

Returns:
modelTrained single-GPU model or None if the model has not

yet been trained.

get_params(deep=True)[source]#

Returns the value of all parameters required to configure this estimator as a dictionary.

Parameters:
deepboolean (default = True)
predict(
X,
threshold=0.5,
layout='depth_first',
default_chunk_size=None,
align_bytes=None,
delayed=True,
broadcast_data=None,
)[source]#

Predicts the labels for X.

Parameters:
XDask cuDF dataframe or CuPy backed Dask Array (n_rows, n_features)

Distributed dense matrix (floats or doubles) of shape (n_samples, n_features).

thresholdfloat (default = 0.5)

Threshold used for classification.

layoutstring (default = ‘depth_first’)

Specifies the in-memory layout of nodes in nvForest models. Options: ‘depth_first’, ‘layered’, ‘breadth_first’.

default_chunk_sizeint, optional (default = None)

Determines how batches are further subdivided for parallel processing. The optimal value depends on hardware, model, and batch size. If None, will be automatically determined.

align_bytesint, optional (default = None)

If specified, trees will be padded such that their in-memory size is a multiple of this value. This can improve performance by guaranteeing that memory reads from trees begin on a cache line boundary. Typical values are 0 or 128.

delayedbool (default = True)

Whether to do a lazy prediction (and return Delayed objects) or an eagerly executed one.

broadcast_databool, optional

Deprecated. This parameter no longer has effect and will be removed in release 26.12.

Returns:
yDask cuDF dataframe or CuPy backed Dask Array (n_rows, 1)

The predicted class labels.

predict_proba(X, delayed=True, **kwargs)[source]#

Predicts the probability of each class for X.

See documentation of predict for notes on performance.

Parameters:
XDask cuDF dataframe or CuPy backed Dask Array (n_rows, n_features)

Distributed dense matrix (floats or doubles) of shape (n_samples, n_features).

delayedbool (default = True)

Whether to do a lazy prediction (True) or an eager prediction (False)

**kwargsdict

Additional predict parameters passed to the underlying model’s predict method. See RandomForestClassifier.predict_proba documentation for a full list.

Returns:
yDask cuDF dataframe or CuPy backed Dask Array (n_rows, n_classes)
set_params(**params)[source]#

Sets the value of parameters required to configure this estimator, it functions similar to the sklearn set_params.

Parameters:
paramsdict of new params.