Data Science · Chapter 32 of 43
Random Forest
A RANDOM FOREST averages many decision trees trained on random subsets of the data and features.
Strong out-of-the-box performance on tabular data — a common first serious model.
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.91Usually 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-ish patterns with less pre-processing than most models.
