Stretch: bagging concept
Beginner classical-mlensemblesrandom-foreststretch
Implement:
def bootstrap_sample(input: np.ndarray, labels: np.ndarray, seed: int | None = None) -> tuple[np.ndarray, np.ndarray]:
"""Resample n_samples rows with replacement."""
def train_random_forest(input, labels, n_trees, max_depth, seed=None) -> list[dict]:
"""Train n_trees independent trees, each on its own bootstrap sample."""
- Reuse
03-best-split-minimal-tree's build_tree, don't reimplement tree construction.
- The returned list is directly usable by
01-random-forest-majority-vote's random_forest_predict.
- Build exactly one random generator, before the loop over trees, not one per tree.