# RandomForestClassifier

### *class* cuml.dask.ensemble.RandomForestClassifier(, workers=None, client=None, verbose=False, n_estimators=100, random_state=None, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/ensemble/randomforestclassifier.py#L18)

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_estimators**
  : total number of trees in the forest

  **split_criterion**
  : 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
    <br/>
    `2`, `'mse'`, `4`, `'poisson'`, `5`, `'gamma'`, `6`,
    `'inverse_gaussian'` not valid for classification

  **bootstrap**
  : 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.
    <br/>
    Weighted bootstrapping through `sample_weight` or `class_weight`
    is not yet supported for distributed random forests.

  **max_samples**
  : Ratio of dataset rows used while fitting each tree.

  **max_depth**
  : Maximum tree depth. Use `None` for unlimited depth (trees grow
    until all leaves are pure). Must be a positive integer or `None`.
    <!-- rapids-pre-commit-hooks: disable-next-line -->
    <br/>
    #### Versionchanged
    Changed in version 26.08: The default of `max_depth` changed from `16` to [`None`](https://docs.python.org/3/builtins/constants.html#None).

  **max_leaves**
  : Maximum leaf nodes per tree. Soft constraint. Unlimited, If `-1`.

  **max_features**
  : 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_bins**
  : Maximum number of bins used by the split algorithm per feature.

  **min_samples_leaf**
  : 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_split**
  : 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.

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

  **random_state**
  : Seed for the random number generator. Unseeded by default.
* **Attributes:**
  **oob_decision_function_**

### Methods

| [`fit`](#cuml.dask.ensemble.RandomForestClassifier.fit)(X, y[, sample_weight])           | Fit the input data with a Random Forest classifier                                                                 |
|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| [`get_params`](#cuml.dask.ensemble.RandomForestClassifier.get_params)([deep])                   | Returns the value of all parameters required to configure this estimator as a dictionary.                          |
| [`predict`](#cuml.dask.ensemble.RandomForestClassifier.predict)(X[, threshold, layout, ...]) | Predicts the labels for X.                                                                                         |
| [`predict_proba`](#cuml.dask.ensemble.RandomForestClassifier.predict_proba)(X[, delayed])          | Predicts the probability of each class for X.                                                                      |
| [`set_params`](#cuml.dask.ensemble.RandomForestClassifier.set_params)(\*\*params)               | Sets the value of parameters required to configure this estimator, it functions similar to the sklearn set_params. |
<!-- !! processed by numpydoc !! -->

#### fit(X, y, sample_weight=None)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/ensemble/randomforestclassifier.py#L128)

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:

```python
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:

```python
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:**
  **X**
  : Distributed dense matrix (floats or doubles) of shape
    (n_samples, n_features).

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

  **sample_weight**
  : Sample weights are not yet supported by distributed random
    forests.

<!-- !! processed by numpydoc !! -->

#### get_combined_model()[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/common/base.py#L57)

Return single-GPU model for serialization

* **Returns:**
  **model**
  : yet been trained.

<!-- !! processed by numpydoc !! -->

#### get_params(deep=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/ensemble/randomforestclassifier.py#L293)

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

* **Parameters:**
  **deep**

<!-- !! processed by numpydoc !! -->

#### predict(X, threshold=0.5, layout='depth_first', default_chunk_size=None, align_bytes=None, delayed=True)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/ensemble/randomforestclassifier.py#L218)

Predicts the labels for X.

* **Parameters:**
  **X**
  : Distributed dense matrix (floats or doubles) of shape
    (n_samples, n_features).

  **threshold**
  : Threshold used for classification.

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

  **default_chunk_size**
  : 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_bytes**
  : 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.

  **delayed**
  : Whether to do a lazy prediction (and return Delayed objects) or an
    eagerly executed one.
* **Returns:**
  **y**
  : The predicted class labels.

<!-- !! processed by numpydoc !! -->

#### predict_proba(X, delayed=True, \*\*kwargs)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/ensemble/randomforestclassifier.py#L267)

Predicts the probability of each class for X.

See documentation of [`predict`](#cuml.dask.ensemble.RandomForestClassifier.predict) for notes on performance.

* **Parameters:**
  **X**
  : Distributed dense matrix (floats or doubles) of shape
    (n_samples, n_features).

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

  **\*\*kwargs**
  : Additional predict parameters passed to the underlying model’s predict method.
    See RandomForestClassifier.predict_proba documentation for a full list.
* **Returns:**
  **y**

<!-- !! processed by numpydoc !! -->

#### set_params(\*\*params)[[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/dask/ensemble/randomforestclassifier.py#L304)

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

* **Parameters:**
  **params**

<!-- !! processed by numpydoc !! -->
