---
name: "mlpack_random_forest"
section: "1"
platform: "linux"
package: "mlpack-bin"
version: "4.6.0-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mlpack_random_forest"
---

# mlpack\_random\_forest(1)

random forests

## NAME

**mlpack\_random\_forest** - random forests

## SYNOPSIS

```
 mlpack_random_forest [-m unknown] [-l unknown] [-D int] [-g double] [-n int] [-N int] [-a bool] [-s int] [-d int] [-T unknown] [-L unknown] [-t unknown] [-V bool] [-w bool] [-M unknown] [-p unknown] [-P unknown] [-h -v]
```

## DESCRIPTION

This program is an implementation of the standard random forest classification algorithm by Leo Breiman. A random forest can be trained and saved for later use, or a random forest may be loaded and predictions or class probabilities for points may be generated.

The training set and associated labels are specified with the '**--training\_file** (**-t**)' and '**--labels\_file** (**-l**)' parameters, respectively. The labels should be in the range \`\[0, num\_classes - 1\]\`. Optionally, if '**--labels\_file** (**-l**)' is not specified, the labels are assumed to be the last dimension of the training dataset.

When a model is trained, the '**--output\_model\_file** (**-M**)' output parameter may be used to save the trained model. A model may be loaded for predictions with the '**--input\_model\_file** (**-m**)'parameter. The '**--input\_model\_file** (**-m**)' parameter may not be specified when the '**--training\_file** (**-t**)' parameter is specified. The '**--minimum\_leaf\_size** (**-n**)' parameter specifies the minimum number of training points that must fall into each leaf for it to be split.  The '**--num\_trees** (**-N**)' controls the number of trees in the random forest. The ’**--minimum\_gain\_split** (**-g**)' parameter controls the minimum required gain for a decision tree node to split. Larger values will force higher-confidence splits. The '**--maximum\_depth** (**-D**)' parameter specifies the maximum depth of the tree. The '**--subspace\_dim** (**-d**)' parameter is used to control the number of random dimensions chosen for an individual node's split. If ’**--print\_training\_accuracy** (**-a**)' is specified, the calculated accuracy on the training set will be printed.

Test data may be specified with the '**--test\_file** (**-T**)' parameter, and if performance measures are desired for that test set, labels for the test points may be specified with the '**--test\_labels\_file** (**-L**)' parameter. Predictions for each test point may be saved via the '**--predictions\_file** (**-p**)'output parameter. Class probabilities for each prediction may be saved with the ’**--probabilities\_file** (**-P**)' output parameter.

For example, to train a random forest with a minimum leaf size of 20 using 10 trees on the dataset contained in 'data.csv'with labels 'labels.csv', saving the output random forest to 'rf\_model.bin' and printing the training error, one could call

$ **mlpack\_random\_forest** **--training\_file** data.csv **--labels\_file** labels.csv **--minimum\_leaf\_size** 20 **--num\_trees** 10 **--output\_model\_file** rf\_model.bin **--print\_training\_accuracy**

Then, to use that model to classify points in 'test\_set.csv' and print the test error given the labels 'test\_labels.csv' using that model, while saving the predictions for each point to 'predictions.csv', one could call

$ **mlpack\_random\_forest** **--input\_model\_file** rf\_model.bin **--test\_file** test\_set.csv **--test\_labels\_file** test\_labels.csv **--predictions\_file** predictions.csv

## OPTIONAL INPUT OPTIONS

- **--help (-h) \[*bool*\]**

  Default help info.

- **--info \[string\]**

  Print help on a specific option. Default value ''.

- **--input\_model\_file (-m) \[*unknown*\]**

  Pre-trained random forest to use for classification.  **--labels\_file** (**-l**) \[*unknown*\] Labels for training dataset.

- **--maximum\_depth (-D) \[*int*\]**

  Maximum depth of the tree (0 means no limit).  Default value 0.

- **--minimum\_gain\_split (-g) \[*double*\]**

  Minimum gain needed to make a split when building a tree. Default value 0.

- **--minimum\_leaf\_size (-n) \[*int*\]**

  Minimum number of points in each leaf node.  Default value 1.

- **--num\_trees (-N) \[*int*\]**

  Number of trees in the random forest. Default value 10.

- **--print\_training\_accuracy (-a) \[*bool*\]**

  If set, then the accuracy of the model on the training set will be predicted (verbose must also be specified).

- **--seed (-s) \[*int*\]**

  Random seed. If 0, 'std::time(NULL)' is used.  Default value 0.

- **--subspace\_dim (-d) \[*int*\]**

  Dimensionality of random subspace to use for each split. '0' will autoselect the square root of data dimensionality. Default value 0.

- **--test\_file (-T) \[*unknown*\]**

  Test dataset to produce predictions for.

- **--test\_labels\_file (-L) \[*unknown*\]**

  Test dataset labels, if accuracy calculation is desired.

- **--training\_file (-t) \[*unknown*\]**

  Training dataset.

- **--verbose (-v) \[*bool*\]**

  Display informational messages and the full list of parameters and timers at the end of execution.

- **--version (-V) \[*bool*\]**

  Display the version of mlpack.

- **--warm\_start (-w) \[*bool*\]**

  If true and passed along with \`training\` and \`input\_model\` then trains more trees on top of existing model.

## OPTIONAL OUTPUT OPTIONS

- **--output\_model\_file (-M) \[*unknown*\]**

  Model to save trained random forest to.

- **--predictions\_file (-p) \[*unknown*\]**

  Predicted classes for each point in the test set.

- **--probabilities\_file (-P) \[*unknown*\]**

  Predicted class probabilities for each point in the test set.

## ADDITIONAL INFORMATION

For further information, including relevant papers, citations, and theory, consult the documentation found at http://www.mlpack.org or included with your distribution of mlpack.
