Implement random forest with OOB and imbalance
AppleData Scientist · OnsiteLast updated
This question evaluates expertise in implementing and engineering a memory- and compute-efficient Random Forest for binary classification, covering ensemble methods, CART/Gini impurity, OOB evaluation and calibration, class-imbalance handling, reproducibility, parallel and thread-safe system design, and streaming/warm-start model updates.
Implement a binary‑classification Random Forest from scratch for N=200,000, d=100 (mixed numerical and high‑cardinality categorical), with a 2 GB memory budget. Requirements: (a) Trees: CART with Gini impurity, max_depth, min_samples_leaf; handle missing values via surrogate splits or median/mode imputation; support categorical splits without one‑hot. (b) Bagging and feature bagging: bootstrap per tree; m_try=⌊√d⌋ at each split; ensure deterministic reproducibility with per‑tree seeds. (c) Out‑of‑bag (OOB) evaluation: compute OOB ROC‑AUC, PR‑AUC, and a reliability diagram; derive class‑probability calibration using OOB Platt scaling vs isotonic—justify when each is preferable. (d) Severe class imbalance: positive rate ≈1%; incorporate a 10× cost for FN vs FP into split selection and sampling (class_weight or stratified bootstrap). (e) Parallelization: design thread‑safe data structures and quantify training/inference complexity and memory; estimate wall‑clock time on 8 cores. (f) Streaming/warm‑start: add trees over time without retraining existing ones; discuss concept‑drift detection with OOB metrics. Provide clear pseudocode for train(), predict_proba(), and OOB evaluation, and justify all design choices.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.