Machine Learning Β· Chapter 14 of 40

Random Forest

A RANDOM FOREST is an ENSEMBLE of many decision trees, each trained on a random subset of data and features. Predictions are averaged (regression) or voted (classification).

Strong out-of-the-box performance on tabular data.

Example 1 (python)
from sklearn.ensemble import RandomForestClassifier
m = RandomForestClassifier(n_estimators=200, random_state=42).fit(X_train, y_train)
print(m.score(X_test, y_test))
Output
0.91

Usually beats a single tree.

Example 2 (python)
print(m.feature_importances_[:5])
Output
[0.12 0.08 0.35 0.02 0.05]

Built-in feature importance.

Key points

  • Ensemble of many trees.
  • Reduces variance vs single tree.
  • Great on tabular data.
  • Provides feature importances.
πŸ’‘ Note: Random forests handle mixed data types and missing values gracefully with less pre-processing than most models.

πŸ“ Quick Quiz

1. A random forest is:

2. It reduces:

3. It provides: