# Random forest classification (/docs/analyses/random-forest-classification)



## When to use it [#when-to-use-it]

Use random forest classification when the outcome is a category and you want holdout accuracy plus which numeric features split the classes, without reading one tree. A single tree is [decision tree](/docs/analyses/decision-tree). The numeric-outcome version is [random forest regression](/docs/analyses/random-forest-regression).

## Assumptions [#assumptions]

The outcome is categorical. Features are numeric. Classes with fewer than two rows are dropped. Holdout fraction 0.25, 100 trees, min\_samples\_leaf 5, no depth cap, `random_state=0`. HTTP and chat dispatch both honour `test_fraction` and `min_samples_leaf`. Kernel and class weights are not exposed.

## Running it in Tensr [#running-it-in-tensr]

<Steps>
  <Step>
    ML → Classification → Random Forest Classification. In chat: “Random forest of passed on hours and anxiety.”
  </Step>

  <Step>
    Target is the categorical column. Features need at least one numeric column.
  </Step>
</Steps>

## Options [#options]

<TypeTable
  type="{
  dependent: {
    type: 'string',
    description: 'Categorical outcome.',
  },
  independents: {
    type: 'string[]',
    description: 'Numeric features. At least one.',
  },
  n_estimators: {
    type: '10–500',
    description: 'Number of trees.',
    default: '100',
  },
  min_samples_leaf: {
    type: '1–100',
    description: 'Minimum rows in a leaf. Maps to ranger min.node.size. No depth cap.',
    default: '5',
  },
  test_fraction: {
    type: '0.05–0.5',
    description: 'Holdout fraction, clamped to 0.10–0.50. HTTP and chat dispatch both honour it. A note is added when the value is clamped.',
    default: '0.25',
  },
  decimal_places: {
    type: '0–6',
    description: 'Report output. Decimal places.',
    default: '3',
  },
  apa_format: {
    type: 'boolean',
    description: 'Report output. APA-style p-values.',
    default: 'true',
  },
  include_charts: {
    type: 'boolean',
    description: 'Report output. Feature-importance chart and, for two classes, an ROC.',
    default: 'true',
  },
}"
/>

## Reading the output [#reading-the-output]

A separate 240-row sample where hours strongly shifts the pass rate. 100 trees, min\_samples\_leaf 5, no depth cap, 25% holdout. Test accuracy should sit clearly above chance.

| Actual \ Predicted |  0 |  1 |
| -----------------: | -: | -: |
|                  0 | 26 |  7 |
|                  1 | 10 | 17 |

| Variable | Importance |
| -------- | ---------: |
| hours    |      0.798 |
| anxiety  |      0.202 |

Train accuracy = 0.9, test accuracy = 0.717, n = 240, trees = 100, min\_samples\_leaf = 5. Hours was built to move the pass rate strongly, so holdout accuracy should sit clearly above chance.

## Reporting (APA 7) [#reporting-apa-7]

Holdout classification of `passed` from hours and anxiety, n = 240. Test accuracy = 0.717, train accuracy = 0.9.

## Coming from SPSS [#coming-from-spss]

SPSS has no random-forest dialog. Tensr’s item is on the ML menu, Classification → Random Forest Classification. The path string stored for this item matches that menu.

## Related [#related]

[Decision tree](/docs/analyses/decision-tree) is one tree. [Gradient boosting](/docs/analyses/gradient-boosting) is the boosting counterpart. [SVM classification](/docs/analyses/svm-classification) is another holdout classifier.
