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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Here is Claude's plan: βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Batch 12.5 β XGBoost Integration Plan
|
| 2 |
+
|
| 3 |
+
Context
|
| 4 |
+
|
| 5 |
+
The current system (models/live_fair_simulator_v3.py) is entirely rule-based and statistical β
|
| 6 |
+
no trained ML models exist. All probabilities are produced by a layered additive simulator:
|
| 7 |
+
batter baseline β pitch-outcome blending β zone/arsenal/family-zone matchups β trajectory
|
| 8 |
+
deception β environment overlay β platoon adjustment β 10K Monte Carlo simulation.
|
| 9 |
+
|
| 10 |
+
Final outputs per batter row: hit_prob, hr_prob, tb2p_prob (plus ~110 diagnostic fields).
|
| 11 |
+
|
| 12 |
+
Batch 12.5 adds XGBoost as a correction/delta layer on top of these outputs. XGBoost learns
|
| 13 |
+
where the rule-based system is systematically wrong. It does not replace any existing logic.
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
Files Inspected
|
| 17 |
+
|
| 18 |
+
ββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 19 |
+
β File β Role β
|
| 20 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 21 |
+
β models/live_fair_simulator_v3.py β Master orchestrator β assembles all features, runs simulation β
|
| 22 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 23 |
+
β models/batter_baseline.py β Batter feature extraction + baseline probs (12A shape) β
|
| 24 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 25 |
+
β models/batter_trend_model.py β 7d/30d rolling metrics + hot/cold/trending flags (12B) β
|
| 26 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 27 |
+
β models/batter_archetype.py β Rule-based archetype classifier (12C) β
|
| 28 |
+
ββββββββββββοΏ½οΏ½βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 29 |
+
β models/pitcher_adjustment.py β Pitcher features + adjustments + 12G contact-shape β
|
| 30 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 31 |
+
β models/trajectory_model.py β Physics-based deception/tunnel/release scores (Batch 10) β
|
| 32 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 33 |
+
β models/environment_model.py β Park + weather + wind overlay (Batch 11) β
|
| 34 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 35 |
+
β models/zone_matchup_model.py β Zone-weighted matchup boosts (Batch 9) β
|
| 36 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 37 |
+
β models/arsenal_matchup_model.py β Arsenal-weighted matchup boosts (Batch 9) β
|
| 38 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 39 |
+
β models/matchup_model.py β Family-zone conditional boosts (Batch 9) β
|
| 40 |
+
ββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 41 |
+
β database/db.py β DuckDB schema β includes recommendation_logs + outcome tables β
|
| 42 |
+
ββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 43 |
+
|
| 44 |
+
---
|
| 45 |
+
1. Feature Inventory
|
| 46 |
+
|
| 47 |
+
Features Stable for ML (v1-eligible)
|
| 48 |
+
|
| 49 |
+
Batter Baseline (from build_batter_feature_row() in batter_baseline.py)
|
| 50 |
+
- ev90 β 90th pct exit velocity
|
| 51 |
+
- avg_launch_angle β mean launch angle
|
| 52 |
+
- barrel_rate β barrel rate
|
| 53 |
+
- hard_hit_rate β hard-hit rate (EV β₯ 95 mph)
|
| 54 |
+
- xwoba β expected wOBA
|
| 55 |
+
- pull_rate, air_ball_rate, pull_air_rate, pulled_hard_air_rate, pulled_barrel_rate
|
| 56 |
+
- plate_appearances β sample size proxy
|
| 57 |
+
- batter_stand (L/R) β handedness (encode as 0/1)
|
| 58 |
+
|
| 59 |
+
Batter Contact-Shape Taxonomy β 12A (from build_batter_feature_row())
|
| 60 |
+
- gb_rate, ld_rate, fb_rate, popup_rate
|
| 61 |
+
- la_sweet_spot_rate, la_optimal_hr_rate
|
| 62 |
+
|
| 63 |
+
Batter Trend β 12B (from build_batter_trend_row())
|
| 64 |
+
- ev90_7d, ev90_30d, barrel_7d, barrel_30d, xwoba_7d, xwoba_30d
|
| 65 |
+
- trend_delta_ev90, trend_delta_barrel
|
| 66 |
+
- trend_sample_size_7d, trend_sample_size_30d
|
| 67 |
+
|
| 68 |
+
Batter Archetype β 12C (from classify_batter_archetype())
|
| 69 |
+
- batter_archetype β encode as 4 one-hot features or ordinal power score
|
| 70 |
+
|
| 71 |
+
Pitcher Baseline (from build_pitcher_feature_row() in pitcher_adjustment.py)
|
| 72 |
+
- ev_allowed, hard_hit_rate_allowed, barrel_rate_allowed
|
| 73 |
+
- avg_release_speed, avg_release_spin_rate, avg_release_extension
|
| 74 |
+
- avg_pfx_x, avg_pfx_z
|
| 75 |
+
- p_throws (L/R) β handedness
|
| 76 |
+
|
| 77 |
+
Pitcher Contact-Shape Allowed β 12G (from build_pitcher_feature_row())
|
| 78 |
+
- gb_rate_allowed, ld_rate_allowed, fb_rate_allowed, popup_rate_allowed
|
| 79 |
+
- la_sweet_spot_allowed_rate, la_optimal_hr_allowed_rate, avg_launch_angle_allowed
|
| 80 |
+
|
| 81 |
+
Matchup Boosts β Batch 9 (from zone/arsenal/family-zone adjustors)
|
| 82 |
+
- zone_hr_boost, zone_hit_boost, zone_tb2p_boost
|
| 83 |
+
- arsenal_hr_boost, arsenal_hit_boost, arsenal_tb2p_boost, arsenal_whiff_risk
|
| 84 |
+
- family_zone_hr_boost, family_zone_hit_boost, family_zone_tb2p_boost, family_zone_whiff_risk
|
| 85 |
+
|
| 86 |
+
Trajectory/Deception β Batch 10 (from build_trajectory_features())
|
| 87 |
+
- deception_score, tunnel_score, release_consistency_score
|
| 88 |
+
|
| 89 |
+
Environment β Batch 11 (from compute_environment_adjustment())
|
| 90 |
+
- park_hr_boost, park_hit_boost, park_tb2p_boost
|
| 91 |
+
- weather_hr_boost, weather_hit_boost, weather_tb2p_boost
|
| 92 |
+
- env_run_env_score
|
| 93 |
+
- wind_direction_bucket (encode as 4 one-hot features: out/in/cross/neutral)
|
| 94 |
+
|
| 95 |
+
Simulator Final Outputs (from live_fair_simulator_v3.py β also serve as delta anchor)
|
| 96 |
+
- hit_prob, hr_prob, tb2p_prob β final clamped simulation outputs; included as features
|
| 97 |
+
AND used as the subtraction anchor for delta targets (see Β§2)
|
| 98 |
+
|
| 99 |
+
Features to Exclude Initially
|
| 100 |
+
|
| 101 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 102 |
+
β Feature β Reason β
|
| 103 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 104 |
+
β hit_prob_base, hr_prob_base, tb2p_prob_base β Intermediate pre-simulation values; the final outputs are the correct anchor (see Β§2) but both are β
|
| 105 |
+
β β deferred from 12.5A dataset β
|
| 106 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 107 |
+
β zone_sample_size, arsenal_sample_size, β Leaky proxy for batter data volume; use plate_appearances instead β
|
| 108 |
+
β family_zone_sample_size β β
|
| 109 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 110 |
+
β batter_hot_flag, batter_cold_flag, β Derived from continuous features already included β redundant β
|
| 111 |
+
β batter_trending_up_flag β β
|
| 112 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 113 |
+
β reason_tags β Free-text, not numerically usable β
|
| 114 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 115 |
+
β stadium_lat, stadium_lon, stadium_name_used β Too granular; park boosts already capture venue effect β
|
| 116 |
+
ββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½βββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 117 |
+
β weather_game_time_used β Boolean metadata, not predictive β
|
| 118 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 119 |
+
β fatigue_score, degradation_score, trust_live_score β Live in-game signals; training data represents pre-game snapshots β
|
| 120 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 121 |
+
β velo_delta, spin_delta, extension_delta β Same reason β live in-game only β
|
| 122 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 123 |
+
β pitch_count, times_through_order β Not available at pre-game prediction time β
|
| 124 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 125 |
+
β All rolling pitch sample sizes β Diagnostic only β
|
| 126 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 127 |
+
β slot (On Deck / In Hole / 3 Away) β Ordering artifact, not a batter quality signal β
|
| 128 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 129 |
+
|
| 130 |
+
---
|
| 131 |
+
2. Recommended Target Design
|
| 132 |
+
|
| 133 |
+
Chosen: Option B β Residual/Delta Correction Model
|
| 134 |
+
|
| 135 |
+
Why not Option A (direct probability)?
|
| 136 |
+
|
| 137 |
+
Direct prediction replaces the simulator. It would require substantial labeled data volume
|
| 138 |
+
to match or exceed simulator accuracy. Premature on first pass.
|
| 139 |
+
|
| 140 |
+
Why not Option C (post-simulation calibration)?
|
| 141 |
+
|
| 142 |
+
Calibration isotonic/Platt scaling is a single monotonic transform per market β it can't
|
| 143 |
+
learn which features drive systematic mis-estimation. Less expressive and harder to audit
|
| 144 |
+
for feature importance.
|
| 145 |
+
|
| 146 |
+
Why Option B (delta/residual) is safest β and why the anchor is the final output
|
| 147 |
+
|
| 148 |
+
Two possible anchors exist:
|
| 149 |
+
|
| 150 |
+
ββββββββββββββββββββββββββββ¬βββββββββββββββββββββββ¬ββοΏ½οΏ½οΏ½ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 151 |
+
β Anchor β Target β Assessment β
|
| 152 |
+
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 153 |
+
β hr_prob_base β realized_hr - β XGBoost would partly re-learn what the simulator already computes (trajectory, environment, platoon, β
|
| 154 |
+
β (pre-simulation) β hr_prob_base β etc.). The residual is not a true correction against the full system. β
|
| 155 |
+
ββββββββββββββββββββββββββββΌβββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 156 |
+
β hr_prob (final clamped β realized_hr - β True residual against the complete current system. XGBoost learns exactly where the full pipeline is β
|
| 157 |
+
β output) β hr_prob β systematically wrong. Correct stacking semantics. β
|
| 158 |
+
ββββββββββββββββββββββββββββ΄βββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 159 |
+
|
| 160 |
+
Recommended anchor: hr_prob, hit_prob, tb2p_prob (final simulator outputs).
|
| 161 |
+
|
| 162 |
+
XGBoost trains to predict:
|
| 163 |
+
target_hr_delta = realized_hr_flag - hr_prob
|
| 164 |
+
target_hit_delta = realized_hit_flag - hit_prob
|
| 165 |
+
target_tb2p_delta = realized_tb2p_flag - tb2p_prob
|
| 166 |
+
|
| 167 |
+
Key properties:
|
| 168 |
+
- XGBoost learns where and why the complete pipeline is systematically wrong
|
| 169 |
+
- Residual is approximately mean-zero if the simulator is well-calibrated β healthy behavior
|
| 170 |
+
- If XGBoost produces near-zero deltas, that is a correct and expected result, not a failure
|
| 171 |
+
- Including hr_prob as a feature AND using it as the anchor basis is not circular: the
|
| 172 |
+
model learns from the same feature space to predict the error of the aggregated output
|
| 173 |
+
- Easy to audit: a model producing large positive deltas in specific feature regimes shows
|
| 174 |
+
exactly what the full system underweights
|
| 175 |
+
- Shadow mode trivial: surface xgb_hr_delta, xgb_hit_delta, xgb_tb2p_delta as debug fields
|
| 176 |
+
- If later approved for blending: final_hr_prob = clamp(hr_prob + blend_weight * xgb_hr_delta, 0.005, 0.25)
|
| 177 |
+
|
| 178 |
+
Note on features: hr_prob, hit_prob, tb2p_prob (final outputs) must be included as
|
| 179 |
+
input features in addition to serving as the anchor. They carry information about the
|
| 180 |
+
simulator's full confidence state. See Β§4.
|
| 181 |
+
|
| 182 |
+
---
|
| 183 |
+
3. Training Dataset Schema
|
| 184 |
+
|
| 185 |
+
Unit of Observation
|
| 186 |
+
|
| 187 |
+
batter-game β one row per (batter_name Γ game_date), aggregated across all plate appearances
|
| 188 |
+
in that game.
|
| 189 |
+
|
| 190 |
+
Rationale: outcome labels exist at the batter-game level (did batter get a hit/HR/XBH in this
|
| 191 |
+
game?). PA-level features are not currently computed.
|
| 192 |
+
|
| 193 |
+
---
|
| 194 |
+
Training Dataset Strategy β Two Tiers
|
| 195 |
+
|
| 196 |
+
Tier 1 (IDEAL): Full historical batter-game universe from Statcast
|
| 197 |
+
|
| 198 |
+
Source: The existing statcast_df already contains an events column recording each
|
| 199 |
+
plate appearance outcome (e.g., 'home_run', 'single', 'double', 'strikeout', etc.).
|
| 200 |
+
|
| 201 |
+
Label derivation (no external data source needed):
|
| 202 |
+
# Group statcast_df by (player_name, game_date)
|
| 203 |
+
# For each batter-game, derive:
|
| 204 |
+
realized_hit = 1 if any events in ('single','double','triple','home_run') else 0
|
| 205 |
+
realized_hr = 1 if any events == 'home_run' else 0
|
| 206 |
+
realized_tb2p = 1 if any events in ('double','triple','home_run') else 0
|
| 207 |
+
|
| 208 |
+
Why this is the correct primary source:
|
| 209 |
+
- Covers ALL batters who appear in the Statcast data, not just those who received a recommendation
|
| 210 |
+
- No selection bias β outcome is independent of whether the system made a prediction that day
|
| 211 |
+
- Labels are derived from the same raw data used to compute features (no new data source needed)
|
| 212 |
+
- Time horizon: full historical Statcast window (configurable)
|
| 213 |
+
|
| 214 |
+
Join key: player_name Γ game_date
|
| 215 |
+
|
| 216 |
+
Feature reconstruction: For each batter-game row, call existing feature pipeline
|
| 217 |
+
functions with reference_date = game_date to reconstruct the feature snapshot at that
|
| 218 |
+
point in time. The pitcher in scope for feature purposes is the starting pitcher of record
|
| 219 |
+
for that game (requires a game-to-starting-pitcher lookup, which can be derived from
|
| 220 |
+
Statcast pitcher field for early-inning pitches).
|
| 221 |
+
|
| 222 |
+
---
|
| 223 |
+
Tier 2 (FALLBACK β biased, use only if Tier 1 is infeasible): batter_prop_outcomes
|
| 224 |
+
|
| 225 |
+
Source: database/batter_prop_outcomes table.
|
| 226 |
+
|
| 227 |
+
Critical limitation β recommendation-sample bias:
|
| 228 |
+
This table only contains batters who were actively recommended by the system. It
|
| 229 |
+
over-represents high-edge matchups, favorable conditions, and high-skill batters. Training
|
| 230 |
+
exclusively on this dataset will produce a model that performs well within the recommendation
|
| 231 |
+
population but may generalize poorly to the broader batter universe.
|
| 232 |
+
|
| 233 |
+
Consequences if used:
|
| 234 |
+
- XGBoost learns to "correct" only in regimes already visited by the recommendation engine
|
| 235 |
+
- Evaluation metrics will look better than they are (test set mirrors training distribution)
|
| 236 |
+
- Model will be systematically uninformed about low-edge or average matchups
|
| 237 |
+
|
| 238 |
+
If Tier 2 is used (data volume insufficient for Tier 1):
|
| 239 |
+
- Explicitly label all evaluation results as "biased sample" β not population-representative
|
| 240 |
+
- Do NOT blend into production based on biased-sample metrics alone
|
| 241 |
+
- Transition to Tier 1 as soon as Statcast event data volume is sufficient (target: 1,000+
|
| 242 |
+
unique batter-game observations)
|
| 243 |
+
|
| 244 |
+
Join keys: game_pk + batter_name + pitcher_name
|
| 245 |
+
|
| 246 |
+
---
|
| 247 |
+
Schema (same for both tiers once assembled)
|
| 248 |
+
|
| 249 |
+
game_pk int row unit key (doubleheader-safe)
|
| 250 |
+
batter_name str row unit key
|
| 251 |
+
pitcher_name str starting pitcher (derived from early-inning pitches)
|
| 252 |
+
pitcher_id int starting pitcher ID (from statcast pitcher column)
|
| 253 |
+
game_date date for chronological split
|
| 254 |
+
home_team str for park factor / venue lookup
|
| 255 |
+
# ---- Labels ----
|
| 256 |
+
realized_hit int 0/1
|
| 257 |
+
realized_hr int 0/1
|
| 258 |
+
realized_tb2p int 0/1
|
| 259 |
+
# ---- Batter baseline ----
|
| 260 |
+
ev90 float NaN if insufficient PA data
|
| 261 |
+
avg_launch_angle float NaN if insufficient PA data
|
| 262 |
+
barrel_rate float NaN if insufficient PA data
|
| 263 |
+
hard_hit_rate float NaN if insufficient PA data
|
| 264 |
+
xwoba float NaN if insufficient PA data
|
| 265 |
+
pull_rate float NaN if insufficient PA data
|
| 266 |
+
air_ball_rate float NaN if insufficient PA data
|
| 267 |
+
pull_air_rate float NaN if insufficient PA data
|
| 268 |
+
pulled_hard_air_rate float NaN if insufficient PA data
|
| 269 |
+
pulled_barrel_rate float NaN if insufficient PA data
|
| 270 |
+
plate_appearances int 0 if no data
|
| 271 |
+
batter_stand_R int 0/1 one-hot
|
| 272 |
+
# ---- 12A contact-shape taxonomy ----
|
| 273 |
+
gb_rate, ld_rate, fb_rate, popup_rate float NaN if insufficient data
|
| 274 |
+
la_sweet_spot_rate, la_optimal_hr_rate float NaN if insufficient data
|
| 275 |
+
# ---- 12B trend ----
|
| 276 |
+
ev90_7d, ev90_30d float NaN if < min sample in window
|
| 277 |
+
barrel_7d, barrel_30d float NaN if < min sample in window
|
| 278 |
+
xwoba_7d, xwoba_30d float NaN if < min sample in window
|
| 279 |
+
trend_delta_ev90, trend_delta_barrel float NaN if window data absent
|
| 280 |
+
trend_sample_size_7d, trend_sample_size_30d int 0 if no data
|
| 281 |
+
# ---- 12C archetype (one-hot) ----
|
| 282 |
+
archetype_power, archetype_contact, archetype_gap, archetype_balanced int 0 if no data
|
| 283 |
+
# ---- Pitcher baseline ----
|
| 284 |
+
ev_allowed, hard_hit_rate_allowed, barrel_rate_allowed float NaN if insufficient data
|
| 285 |
+
avg_release_speed, avg_release_spin_rate, avg_release_extension float NaN if insufficient data
|
| 286 |
+
avg_pfx_x, avg_pfx_z float NaN if insufficient data
|
| 287 |
+
p_throws_R int 0/1 one-hot
|
| 288 |
+
# ---- 12G contact-shape allowed ----
|
| 289 |
+
gb_rate_allowed, ld_rate_allowed, fb_rate_allowed, popup_rate_allowed float NaN if insufficient data
|
| 290 |
+
la_sweet_spot_allowed_rate, la_optimal_hr_allowed_rate float NaN if insufficient data
|
| 291 |
+
avg_launch_angle_allowed float NaN if insufficient data
|
| 292 |
+
# ---- Batch 9 matchup boosts ----
|
| 293 |
+
zone_hr_boost, zone_hit_boost, zone_tb2p_boost float NaN if no zone data
|
| 294 |
+
arsenal_hr_boost, arsenal_hit_boost, arsenal_tb2p_boost, arsenal_whiff_risk float NaN if no data
|
| 295 |
+
family_zone_hr_boost, family_zone_hit_boost, family_zone_tb2p_boost, family_zone_whiff_risk float NaN if no data
|
| 296 |
+
# ---- Batch 10 trajectory ----
|
| 297 |
+
deception_score, tunnel_score, release_consistency_score float NaN if insufficient kinematic data
|
| 298 |
+
# ---- Batch 11 environment (park only β weather excluded) ----
|
| 299 |
+
park_hr_boost, park_hit_boost, park_tb2p_boost float derived from home_team venue lookup
|
| 300 |
+
env_run_env_score float park-only score
|
| 301 |
+
# ---- Simulator anchor (EXCLUDED from 12.5A) ----
|
| 302 |
+
# hit_prob, hr_prob, tb2p_prob: deferred β requires full game context for faithful reconstruction
|
| 303 |
+
# Will be addressed in 12.5B planning after reviewing dataset audit
|
| 304 |
+
|
| 305 |
+
Leakage Prevention
|
| 306 |
+
|
| 307 |
+
- Chronological split only β never random split; use earliest N% of dates for train
|
| 308 |
+
- reference_date for build_batter_trend_row() must be set to game_date, not today
|
| 309 |
+
- trend_7d features use game_date - 7d lookback; enforced via the existing reference_date
|
| 310 |
+
parameter in batter_trend_model.py
|
| 311 |
+
- No features that include same-game outcomes (no post-game stats, no final scores)
|
| 312 |
+
- Statcast data sliced to < game_date when computing per-batter feature rows β never
|
| 313 |
+
"current full dataset"
|
| 314 |
+
- hr_prob / hit_prob / tb2p_prob anchor fields must be reconstructed by running the
|
| 315 |
+
simulator against the Statcast slice at game_date β do NOT use today's simulator output
|
| 316 |
+
as a proxy for historical games
|
| 317 |
+
|
| 318 |
+
Train/Validation Split
|
| 319 |
+
|
| 320 |
+
- Temporal split strictly by game_date
|
| 321 |
+
- Train: all observations before a cutoff date (e.g., first 80% chronologically)
|
| 322 |
+
- Validation: remaining 20% (most recent games)
|
| 323 |
+
- No k-fold cross-validation in v1 β temporal validity matters more than variance reduction
|
| 324 |
+
|
| 325 |
+
Missing Value Handling
|
| 326 |
+
|
| 327 |
+
Default: leave NaN as NaN. Rely on XGBoost's native missing-value routing.
|
| 328 |
+
|
| 329 |
+
XGBoost with tree_method='hist' handles NaN natively β it learns the optimal split
|
| 330 |
+
direction for missing values during training. This is preferable to imputation for v1
|
| 331 |
+
because imputation bakes in assumptions about what "no data" means for each field.
|
| 332 |
+
|
| 333 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 334 |
+
β Field group β When NaN β Handling β
|
| 335 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 336 |
+
β Batter trend features (ev90_7d, trend_delta_*, β Batter has < min sample in window β Leave NaN β XGBoost learns routing β
|
| 337 |
+
β etc.) β β β
|
| 338 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 339 |
+
β Trajectory scores (deception_score, tunnel_score, β Pitcher has insufficient kinematic β Leave NaN β XGBoost learns routing β
|
| 340 |
+
β etc.) β data β β
|
| 341 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 342 |
+
β Matchup boosts (zone, arsenal, family-zone) β Sample size = 0 (no zone data) β Set to 0.0 β a zero boost is semantically correct (no adjustment β
|
| 343 |
+
β β β applied) β
|
| 344 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββοΏ½οΏ½οΏ½βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 345 |
+
β Batter/pitcher rates (ev90, barrel_rate, etc.) β Batter/pitcher not in Statcast β Leave NaN β XGBoost learns routing β
|
| 346 |
+
β β window β β
|
| 347 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 348 |
+
|
| 349 |
+
Do NOT impute trend features to season average. The absence of 7d trend data is itself
|
| 350 |
+
informative (e.g., new batter, injured return). Imputing to the average erases that signal.
|
| 351 |
+
|
| 352 |
+
Do NOT impute trajectory to 0.5. A missing deception score means "unknown" β not
|
| 353 |
+
"average deception." The XGBoost routing for NaN will naturally group unknown-trajectory
|
| 354 |
+
batters together and learn the appropriate correction for that regime.
|
| 355 |
+
|
| 356 |
+
---
|
| 357 |
+
4. First-Pass Feature List (v1)
|
| 358 |
+
|
| 359 |
+
Include in v1 (39 numeric features after encoding)
|
| 360 |
+
|
| 361 |
+
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 362 |
+
β Group β Features β
|
| 363 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 364 |
+
β Batter quality β ev90, barrel_rate, hard_hit_rate, xwoba, pull_air_rate, pulled_barrel_rate, batter_stand_R β
|
| 365 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 366 |
+
β 12A contact-shape β gb_rate, ld_rate, fb_rate, popup_rate, la_sweet_spot_rate, la_optimal_hr_rate β
|
| 367 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 368 |
+
β 12B trend β ev90_7d, trend_delta_ev90, trend_delta_barrel, trend_sample_size_7d β
|
| 369 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 370 |
+
β 12C archetype β archetype_power, archetype_contact, archetype_gap (balanced = reference) β
|
| 371 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 372 |
+
β Pitcher quality β ev_allowed, barrel_rate_allowed, avg_release_speed, avg_pfx_z, p_throws_R β
|
| 373 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 374 |
+
β 12G shape allowed β gb_rate_allowed, fb_rate_allowed, la_optimal_hr_allowed_rate β
|
| 375 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 376 |
+
β Batch 9 matchup β zone_hr_boost, arsenal_hr_boost, family_zone_hr_boost, arsenal_whiff_risk β
|
| 377 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 378 |
+
β Batch 10 traj β deception_score, tunnel_score β
|
| 379 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 380 |
+
β Batch 11 env β park_hr_boost, env_run_env_score (park-only; weather/wind excluded β not reconstructed for historical rows) β
|
| 381 |
+
βββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 382 |
+
β Simulator final outputs β Deferred β requires faithful full-context reconstruction. To be addressed in 12.5B planning. β
|
| 383 |
+
βββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 384 |
+
|
| 385 |
+
Deferred to v2+
|
| 386 |
+
|
| 387 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 388 |
+
β Feature β Reason for deferral β
|
| 389 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 390 |
+
β Full 7d/30d xwoba/barrel windows β Reduce noise; use only deltas and 7d in v1 β
|
| 391 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 392 |
+
β Full hit/tb2p matchup boosts β Add after hr model validates β reduce dimensionality β
|
| 393 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 394 |
+
β avg_launch_angle, avg_pfx_x β Correlated with shape rates already included β
|
| 395 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½βββββββββββββ€
|
| 396 |
+
β Weather sub-fields (wind_cross, wind_neutral) β Add after initial evaluation β
|
| 397 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 398 |
+
β Pitcher spin rate, extension β Add only if feature importance shows signal β
|
| 399 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 400 |
+
|
| 401 |
+
---
|
| 402 |
+
5. Inference Integration Plan
|
| 403 |
+
|
| 404 |
+
Phase 1: Shadow Mode Only (mandatory, no production blending)
|
| 405 |
+
|
| 406 |
+
XGBoost inference runs alongside the existing simulator in
|
| 407 |
+
live_fair_simulator_v3.build_upcoming_simulated_rows() but outputs are added as NEW
|
| 408 |
+
debug fields β they do NOT modify hit_prob, hr_prob, or tb2p_prob.
|
| 409 |
+
|
| 410 |
+
New shadow output fields added to the result row:
|
| 411 |
+
xgb_hr_delta # predicted correction to hr_prob (residual vs full simulator)
|
| 412 |
+
xgb_hit_delta # predicted correction to hit_prob
|
| 413 |
+
xgb_tb2p_delta # predicted correction to tb2p_prob
|
| 414 |
+
xgb_hr_adjusted # = hr_prob + xgb_hr_delta (display only, not used in production)
|
| 415 |
+
xgb_confidence # model confidence proxy (stddev across trees or calibrated)
|
| 416 |
+
xgb_top_features # top 3 feature importances for this prediction (SHAP or gain)
|
| 417 |
+
|
| 418 |
+
Where inference runs:
|
| 419 |
+
- models/xgb_inference.py β new module exposing predict_xgb_deltas(feature_row: dict) -> dict
|
| 420 |
+
- Called from live_fair_simulator_v3.py inside build_upcoming_simulated_rows() after the
|
| 421 |
+
existing simulation block, guarded by if XGB_SHADOW_MODE_ENABLED: flag
|
| 422 |
+
- Model artifact loaded once at startup: models/artifacts/xgb_hr_v1.json, etc.
|
| 423 |
+
- If model file is missing or inference throws, log warning and skip silently β no crash
|
| 424 |
+
|
| 425 |
+
Flag default: XGB_SHADOW_MODE_ENABLED = False until model is trained and evaluated.
|
| 426 |
+
Enabled by setting env var XGB_SHADOW=1 or a config flag in config.py.
|
| 427 |
+
|
| 428 |
+
Phase 2: Audit before any blending
|
| 429 |
+
|
| 430 |
+
Before any blending:
|
| 431 |
+
- Run shadow mode for minimum 2 weeks of live predictions
|
| 432 |
+
- Compare xgb_hr_adjusted vs hr_prob vs realized_hr in batter_prop_outcomes
|
| 433 |
+
- Only proceed to blending if XGBoost log loss and Brier score beat the baseline
|
| 434 |
+
|
| 435 |
+
Phase 3 (future, not in Batch 12.5): Light blend
|
| 436 |
+
|
| 437 |
+
BLEND_WEIGHT = 0.15 # conservative; tune via validation
|
| 438 |
+
final_hr_prob = clamp(hr_prob + BLEND_WEIGHT * xgb_hr_delta, 0.005, 0.25)
|
| 439 |
+
|
| 440 |
+
---
|
| 441 |
+
6. Evaluation Plan
|
| 442 |
+
|
| 443 |
+
Primary Metrics
|
| 444 |
+
|
| 445 |
+
βββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 446 |
+
β Metric β Target β
|
| 447 |
+
βββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 448 |
+
β Log loss β Lower than baseline simulator log loss on held-out test set β
|
| 449 |
+
βββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 450 |
+
β Brier score β Lower than baseline on all three markets β
|
| 451 |
+
βββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 452 |
+
β AUC-ROC β > 0.55 on hr market (binary classification check) β
|
| 453 |
+
βββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 454 |
+
β Calibration β Mean predicted delta near 0; no systematic over/under-prediction by bucket β
|
| 455 |
+
βββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 456 |
+
|
| 457 |
+
Calibration Analysis
|
| 458 |
+
|
| 459 |
+
- Bucket predictions into deciles by xgb_hr_delta
|
| 460 |
+
- For each bucket: plot mean predicted delta vs mean realized delta
|
| 461 |
+
- A flat/diagonal calibration curve is success; systematic skew indicates overfitting or feature leakage
|
| 462 |
+
|
| 463 |
+
Ranking / Edge Utility
|
| 464 |
+
|
| 465 |
+
- Sort candidates by xgb_hr_adjusted on held-out dates
|
| 466 |
+
- Compare top-10% predictions: actual HR rate vs base rate vs hr_prob model
|
| 467 |
+
- Lift metric: mean realized HR rate in top-decile predictions / overall mean HR rate
|
| 468 |
+
|
| 469 |
+
Feature Importance Review (required before production)
|
| 470 |
+
|
| 471 |
+
- SHAP values for top 20 features per target market
|
| 472 |
+
- Sanity check: hr_prob should rank high (it is the most direct summary of the full system)
|
| 473 |
+
- Any feature with near-zero SHAP importance across all samples should be dropped in v2
|
| 474 |
+
|
| 475 |
+
Side-by-Side Comparison
|
| 476 |
+
|
| 477 |
+
- For every held-out game: surface hr_prob (current) vs xgb_hr_adjusted (shadow)
|
| 478 |
+
- Track: which model had lower absolute error per game
|
| 479 |
+
- Aggregate by stadium, pitcher handedness, batter archetype β look for systematic wins
|
| 480 |
+
|
| 481 |
+
Definition of "Success" for First-Pass XGBoost
|
| 482 |
+
|
| 483 |
+
1. Log loss on held-out set β₯ 5% lower than baseline across all three markets
|
| 484 |
+
2. No feature with > 40% importance concentration (guards against single-feature overfitting)
|
| 485 |
+
3. Calibration plot shows no systematic bias > Β±0.03 in any bucket
|
| 486 |
+
4. SHAP values are interpretable and domain-sensible (e.g., high barrel_rate β positive HR delta)
|
| 487 |
+
|
| 488 |
+
Justification for Production Blending (future gate)
|
| 489 |
+
|
| 490 |
+
Only proceed to Phase 3 blending when:
|
| 491 |
+
- All success criteria above are met on β₯ 30 days of held-out data
|
| 492 |
+
- Shadow mode confirmed stable for β₯ 14 days without inference errors
|
| 493 |
+
- Manual audit of high-delta rows shows no obvious data artifacts or leakage
|
| 494 |
+
|
| 495 |
+
---
|
| 496 |
+
7. Safety / Guardrails
|
| 497 |
+
|
| 498 |
+
Not replacing the current system
|
| 499 |
+
|
| 500 |
+
- All existing simulator logic in live_fair_simulator_v3.py is untouched
|
| 501 |
+
- XGBoost inference is additive β gated behind XGB_SHADOW_MODE_ENABLED flag
|
| 502 |
+
- If model file missing: graceful skip, no exception propagation
|
| 503 |
+
|
| 504 |
+
Avoiding double-counting simulator outputs
|
| 505 |
+
|
| 506 |
+
- Input features include the raw intermediate signals (batter rates, pitcher rates, boosts,
|
| 507 |
+
scores) AND the final simulator outputs (hit_prob, hr_prob, tb2p_prob)
|
| 508 |
+
- The final outputs are included as features deliberately β they encode the simulator's full
|
| 509 |
+
aggregated view, which XGBoost uses to learn what the aggregation missed
|
| 510 |
+
- The delta target is realized - final_prob, so XGBoost learns corrections on top of
|
| 511 |
+
the existing aggregation, not as a replacement for it
|
| 512 |
+
- Intermediate _base probabilities are excluded as features (redundant given final outputs)
|
| 513 |
+
|
| 514 |
+
Leakage prevention
|
| 515 |
+
|
| 516 |
+
- Chronological train/val split β strictly no future data in training
|
| 517 |
+
- reference_date parameter used correctly in build_batter_trend_row() (already exists)
|
| 518 |
+
- No post-game features (final scores, realized outcomes) in the feature row
|
| 519 |
+
- All feature functions use historical Statcast sliced to game_date, not today's full dataset
|
| 520 |
+
|
| 521 |
+
Overfitting recent noise
|
| 522 |
+
|
| 523 |
+
- Minimum 30-day training window enforced
|
| 524 |
+
- Early stopping on validation loss (XGBoost early_stopping_rounds=50)
|
| 525 |
+
- max_depth capped at 4 for first pass (shallow trees = less overfitting)
|
| 526 |
+
- subsample=0.8, colsample_bytree=0.7 for regularization
|
| 527 |
+
|
| 528 |
+
Explainability
|
| 529 |
+
|
| 530 |
+
- SHAP values computed for every inference call in shadow mode
|
| 531 |
+
- Surfaced as xgb_top_features in output row (top 3 feature names + SHAP values)
|
| 532 |
+
- Feature importance logged at training time and stored alongside model artifact
|
| 533 |
+
|
| 534 |
+
---
|
| 535 |
+
8. Phased Execution Plan
|
| 536 |
+
|
| 537 |
+
Current execution scope: 12.5A only.
|
| 538 |
+
Batches 12.5Bβ12.5E are designed but NOT being implemented yet.
|
| 539 |
+
Gate: 12.5B proceeds only after the 12.5A audit summary is reviewed and approved.
|
| 540 |
+
|
| 541 |
+
---
|
| 542 |
+
12.5A β Dataset Builder (CURRENT SCOPE)
|
| 543 |
+
|
| 544 |
+
Objective: Produce a clean historical training dataset plus a dataset audit summary.
|
| 545 |
+
No model training. No inference integration. No changes to live_fair_simulator_v3.py.
|
| 546 |
+
|
| 547 |
+
---
|
| 548 |
+
Data Sources
|
| 549 |
+
|
| 550 |
+
Raw Statcast data (data/statcast.py β fetch_statcast_range() or the bulk CSV files
|
| 551 |
+
data/batter_savant_data.csv / data/pitcher_savant_data.csv).
|
| 552 |
+
|
| 553 |
+
Key confirmed columns present in raw Statcast fetch output (verified in normalize_statcast):
|
| 554 |
+
- events β plate appearance outcome (last pitch of PA only; NaN on intermediate pitches)
|
| 555 |
+
- player_name β batter name
|
| 556 |
+
- game_date, game_pk
|
| 557 |
+
- home_team β needed for park factor lookup
|
| 558 |
+
- pitcher β pitcher ID (for starting pitcher identification)
|
| 559 |
+
- launch_speed, launch_angle, estimated_woba_using_speedangle, bb_type
|
| 560 |
+
- release_speed, release_spin_rate, pfx_x, pfx_z, etc.
|
| 561 |
+
|
| 562 |
+
Important: The feature pipeline functions (build_batter_feature_row, build_pitcher_feature_row,
|
| 563 |
+
build_batter_trend_row, etc.) use raw column names (e.g., estimated_woba_using_speedangle,
|
| 564 |
+
stand, bb_type), not the normalized versions. The dataset builder must use the raw
|
| 565 |
+
(unnormalized) statcast DataFrame β do NOT pass normalize_statcast() output to feature functions.
|
| 566 |
+
|
| 567 |
+
---
|
| 568 |
+
Label Derivation (Tier 1 β unbiased)
|
| 569 |
+
|
| 570 |
+
Row unit key: (game_pk, batter_name) β not (player_name, game_date).
|
| 571 |
+
Doubleheaders produce two distinct game_pk values on the same date for the same player.
|
| 572 |
+
Using game_date as the key would merge them, corrupting labels.
|
| 573 |
+
|
| 574 |
+
# 1. Filter to PA-final rows only (events is populated on last pitch of each PA)
|
| 575 |
+
pa_df = statcast_df[statcast_df['events'].notna()].copy()
|
| 576 |
+
|
| 577 |
+
# 2. Group by (game_pk, player_name) β one row per batter-game
|
| 578 |
+
for each (game_pk, player_name) group:
|
| 579 |
+
realized_hit = 1 if any events in {'single','double','triple','home_run'} else 0
|
| 580 |
+
realized_hr = 1 if 'home_run' in events else 0
|
| 581 |
+
realized_tb2p = 1 if any events in {'double','triple','home_run'} else 0
|
| 582 |
+
game_date = group['game_date'].iloc[0] # for chronological splitting
|
| 583 |
+
home_team = group['home_team'].iloc[0] # for park factor lookup
|
| 584 |
+
|
| 585 |
+
# 3. Starting pitcher: pitcher_id from pitches in inning <= 3
|
| 586 |
+
# Use mode() for robustness (handles cases where SP exits early inning)
|
| 587 |
+
|
| 588 |
+
Volume check (first output of 12.5A):
|
| 589 |
+
- Report total unique batter-game rows
|
| 590 |
+
- If < 300 unique batter-game observations β flag in audit; do NOT auto-fall back
|
| 591 |
+
- Report volume and let user decide whether to proceed to Tier 2
|
| 592 |
+
|
| 593 |
+
---
|
| 594 |
+
Tier 2 Fallback (biased β only if Tier 1 volume insufficient)
|
| 595 |
+
|
| 596 |
+
Source: batter_prop_outcomes + recommendation_logs joined by game_pk + batter_name.
|
| 597 |
+
|
| 598 |
+
All evaluation outputs tagged "biased_sample=True" in the audit report.
|
| 599 |
+
Do NOT proceed to 12.5B with Tier 2 data alone without explicit user confirmation.
|
| 600 |
+
|
| 601 |
+
---
|
| 602 |
+
Feature Reconstruction
|
| 603 |
+
|
| 604 |
+
For each (game_pk, batter_name, pitcher_id, game_date, home_team) row:
|
| 605 |
+
|
| 606 |
+
1. Leakage boundary: Slice statcast to statcast_df[statcast_df['game_date'] < game_date].
|
| 607 |
+
All feature functions receive only data prior to the game date.
|
| 608 |
+
2. Call these existing functions with the sliced data:
|
| 609 |
+
- build_batter_feature_row(slice_df, player_name) β batter baseline + 12A shape
|
| 610 |
+
- build_batter_trend_row(slice_df, player_name, reference_date=game_date) β 12B trend
|
| 611 |
+
- classify_batter_archetype(batter_feature_row) β 12C archetype
|
| 612 |
+
- build_pitcher_feature_row(slice_df, pitcher_name, pitcher_id) β pitcher baseline + 12G
|
| 613 |
+
- build_batter_zone_feature_row(slice_df, player_name) + build_pitcher_zone_feature_row(...) β zone inputs
|
| 614 |
+
- compute_zone_matchup_adjustment(batter_zone_row, pitcher_zone_row) β Batch 9 zone boosts
|
| 615 |
+
- build_batter_arsenal_feature_row(...) + build_pitcher_arsenal_feature_row(...) β arsenal inputs
|
| 616 |
+
- compute_arsenal_matchup_adjustment(...) β Batch 9 arsenal boosts
|
| 617 |
+
- build_batter_family_zone_feature_row(...) + build_pitcher_family_zone_feature_row(...) β family-zone inputs
|
| 618 |
+
- compute_family_zone_matchup_adjustment(...) β Batch 9 family-zone boosts
|
| 619 |
+
- build_trajectory_features(slice_df, pitcher_name, pitcher_id) β Batch 10 deception scores
|
| 620 |
+
- compute_park_adjustment(venue_name) β park boosts only (Batch 11 partial)
|
| 621 |
+
- home_team β venue name via models/stadium_lookup.py
|
| 622 |
+
3. Simulator anchor probabilities (hr_prob, hit_prob, tb2p_prob):
|
| 623 |
+
NOT computed in 12.5A. These require the full game context (live weather, lineup order,
|
| 624 |
+
pitch count, etc.) to be meaningful. Reconstructing them with weather=0.0 would produce
|
| 625 |
+
a contaminated anchor. Excluded from the 12.5A dataset. The anchor strategy will be
|
| 626 |
+
decided in post-12.5A review / 12.5B planning after assessing feasibility.
|
| 627 |
+
4. Low-history batters: Include all batter-game rows regardless of historical PA count.
|
| 628 |
+
Feature functions return NaN/None for insufficient data β propagate as-is. Do NOT filter.
|
| 629 |
+
|
| 630 |
+
NaN propagation: No imputation. All NaN/None values pass through as NaN to the Parquet
|
| 631 |
+
file. XGBoost native handling applies at training time (12.5B).
|
| 632 |
+
|
| 633 |
+
---
|
| 634 |
+
Files to Create
|
| 635 |
+
|
| 636 |
+
βββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
|
| 637 |
+
β File β Purpose β
|
| 638 |
+
βββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ€
|
| 639 |
+
β models/xgb_dataset_builder.py β Dataset construction pipeline β
|
| 640 |
+
βββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββ
|
| 641 |
+
|
| 642 |
+
Key functions in models/xgb_dataset_builder.py:
|
| 643 |
+
derive_batter_game_labels(statcast_df) -> pd.DataFrame
|
| 644 |
+
# Filters to PA-final rows (events notna)
|
| 645 |
+
# Groups by (game_pk, player_name)
|
| 646 |
+
# Returns (game_pk, batter_name, game_date, home_team, pitcher_id,
|
| 647 |
+
# realized_hit, realized_hr, realized_tb2p)
|
| 648 |
+
# ALL batter-game rows included β no PA threshold filtering
|
| 649 |
+
|
| 650 |
+
build_feature_row(statcast_df, batter_name, pitcher_id, game_date, home_team) -> dict
|
| 651 |
+
# Slices statcast to game_date < game_date (leakage boundary)
|
| 652 |
+
# Calls all existing feature functions with sliced data + reference_date=game_date
|
| 653 |
+
# Returns full feature dict; NaN values preserved as-is (no imputation)
|
| 654 |
+
# Does NOT compute hit_prob / hr_prob / tb2p_prob
|
| 655 |
+
|
| 656 |
+
build_training_dataset(statcast_df, start_date=None, end_date=None) -> pd.DataFrame
|
| 657 |
+
# Orchestrates: derive_batter_game_labels β build_feature_row per row
|
| 658 |
+
# Returns assembled DataFrame; saves to data/xgb_training_data_v1.parquet
|
| 659 |
+
|
| 660 |
+
audit_training_dataset(df) -> dict
|
| 661 |
+
# Prints and returns audit summary (see below)
|
| 662 |
+
|
| 663 |
+
Files read (not modified):
|
| 664 |
+
All functions in models/batter_baseline.py, models/batter_trend_model.py,
|
| 665 |
+
models/batter_archetype.py, models/pitcher_adjustment.py, models/trajectory_model.py,
|
| 666 |
+
models/zone_matchup_model.py, models/arsenal_matchup_model.py, models/matchup_model.py,
|
| 667 |
+
features/park_factors.py
|
| 668 |
+
|
| 669 |
+
Files NOT touched: models/live_fair_simulator_v3.py β zero modifications in 12.5A.
|
| 670 |
+
|
| 671 |
+
---
|
| 672 |
+
Output Files
|
| 673 |
+
|
| 674 |
+
βββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββ
|
| 675 |
+
β File β Description β
|
| 676 |
+
βββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββ€
|
| 677 |
+
β data/xgb_training_data_v1.parquet β Clean training dataset β
|
| 678 |
+
βββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββ€
|
| 679 |
+
β (printed to console) β Dataset audit summary β
|
| 680 |
+
βββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββββββ
|
| 681 |
+
|
| 682 |
+
---
|
| 683 |
+
Dataset Audit Summary (required output)
|
| 684 |
+
|
| 685 |
+
audit_training_dataset(df) must print/return:
|
| 686 |
+
|
| 687 |
+
=== Batch 12.5A Dataset Audit ===
|
| 688 |
+
Tier used: Tier 1 (Statcast events) / Tier 2 (batter_prop_outcomes)
|
| 689 |
+
Date range: YYYY-MM-DD to YYYY-MM-DD
|
| 690 |
+
Total batter-game rows: N
|
| 691 |
+
Unique batters: N
|
| 692 |
+
Unique pitchers: N
|
| 693 |
+
Unique games (game_pk): N
|
| 694 |
+
|
| 695 |
+
--- Label Distribution ---
|
| 696 |
+
realized_hit positive rate: X.X% (expected ~28% for full MLB universe)
|
| 697 |
+
realized_hr positive rate: X.X% (expected ~4-5%)
|
| 698 |
+
realized_tb2p positive rate: X.X% (expected ~10%)
|
| 699 |
+
|
| 700 |
+
--- Missingness by Feature Group ---
|
| 701 |
+
Batter baseline (ev90, barrel_rate, xwoba): X.X% NaN
|
| 702 |
+
12A contact-shape (gb_rate, etc.): X.X% NaN
|
| 703 |
+
12B trend (ev90_7d, trend_delta_*): X.X% NaN
|
| 704 |
+
Pitcher baseline (ev_allowed, etc.): X.X% NaN
|
| 705 |
+
12G shape allowed: X.X% NaN
|
| 706 |
+
Batch 9 matchup boosts: X.X% NaN (or 0.0)
|
| 707 |
+
Batch 10 trajectory (deception_score): X.X% NaN
|
| 708 |
+
Batch 11 park boosts: X.X% NaN
|
| 709 |
+
|
| 710 |
+
--- Leakage Check ---
|
| 711 |
+
Any feature rows with game_date data used: PASS / FAIL
|
| 712 |
+
Trend reference_date correctly set: PASS / FAIL
|
| 713 |
+
|
| 714 |
+
--- Volume Assessment ---
|
| 715 |
+
Tier 1 feasibility: [SUFFICIENT / INSUFFICIENT β explain why]
|
| 716 |
+
Proceed to 12.5B: [YES if rows >= 300 and labels are reasonable / NO + reason]
|
| 717 |
+
|
| 718 |
+
---
|
| 719 |
+
Known Risks / Runtime Concerns
|
| 720 |
+
|
| 721 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 722 |
+
β Risk β Mitigation β
|
| 723 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 724 |
+
β Column name mismatch: feature functions use raw column names (stand, β Dataset builder passes raw (unnormalized) statcast directly; β
|
| 725 |
+
β estimated_woba_using_speedangle, bb_type); normalize_statcast() renames these β explicitly documented in code β
|
| 726 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββοΏ½οΏ½οΏ½ββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 727 |
+
β events = NaN on intermediate pitches: most statcast rows have events = NaN (non-final β Filter events.notna() before grouping in β
|
| 728 |
+
β pitches) β derive_batter_game_labels β
|
| 729 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 730 |
+
β Doubleheaders: same player, same date, two different game_pk β Unit key is (game_pk, batter_name) β not (player_name, β
|
| 731 |
+
β β game_date) β
|
| 732 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 733 |
+
β WBC fallback limited volume: if data source is only the 2023 WBC window (~16 days, β Audit report volume check; do NOT auto-fallback β report and β
|
| 734 |
+
β ~50β200 batter-games), training will be infeasible β await user decision β
|
| 735 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 736 |
+
β Pitcher identification: pitcher column in raw Statcast is pitcher ID (integer); β Use pitcher_id directly; pitcher_name resolved from statcast β
|
| 737 |
+
β build_pitcher_feature_row also accepts pitcher_id β player_name on pitcher-type rows if needed β
|
| 738 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 739 |
+
β Runtime: slicing statcast per batter-game is O(N Γ M) where N=batter-games, M=rows in β Pre-group statcast by game_date for fast slicing; log progress β
|
| 740 |
+
β full statcast β β
|
| 741 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
| 742 |
+
β Low-history batters: feature functions return NaN for batters with < min data β Include all rows β NaN propagates naturally; missingness β
|
| 743 |
+
β β reported in audit β
|
| 744 |
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 745 |
+
|
| 746 |
+
---
|
| 747 |
+
12.5Bβ12.5E (Designed, Not Yet Executing)
|
| 748 |
+
|
| 749 |
+
These phases are fully designed in Β§Β§ 2β7 of this plan but are gated on 12.5A audit review.
|
| 750 |
+
|
| 751 |
+
- 12.5B β Training pipeline (models/xgb_trainer.py)
|
| 752 |
+
- 12.5C β Offline evaluation (models/xgb_evaluator.py)
|
| 753 |
+
- 12.5D β Shadow-mode inference (models/xgb_inference.py + ~15-line hook in simulator)
|
| 754 |
+
- 12.5E β Light blend (Batch 13+, not in scope)
|
| 755 |
+
|
| 756 |
+
---
|
| 757 |
+
9. Final Recommendations
|
| 758 |
+
|
| 759 |
+
Current Execution
|
| 760 |
+
|
| 761 |
+
Implement 12.5A only. Do not proceed to 12.5B until the audit summary is reviewed.
|
| 762 |
+
Decision gate: does Tier 1 produce β₯ 300 batter-game rows with reasonable label rates?
|
| 763 |
+
|
| 764 |
+
What Is Deferred (not in current scope)
|
| 765 |
+
|
| 766 |
+
- 12.5B: training pipeline
|
| 767 |
+
- 12.5C: offline evaluation
|
| 768 |
+
- 12.5D: shadow-mode inference integration
|
| 769 |
+
- 12.5E: light blend
|
| 770 |
+
- Any production blending β strictly post-audit
|
| 771 |
+
- xgb_feature_snapshots logging table β design deferred to 12.5D+
|
| 772 |
+
|
| 773 |
+
Shadow Mode: Mandatory When Reached
|
| 774 |
+
|
| 775 |
+
Shadow mode is non-negotiable before any probability change. Gated on 12.5C passing all
|
| 776 |
+
success criteria and β₯14 days of stable shadow observation.
|
| 777 |
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 778 |
+
|
| 779 |
+
Claude has written up a plan and is ready to execute. Would you like to proceed?
|
| 780 |
+
|
| 781 |
+
1. Yes, clear context (52% used) and auto-accept edits
|
| 782 |
+
2. Yes, auto-accept edits
|
| 783 |
+
3. Yes, manually approve edits
|
| 784 |
+
β― 4. Type here to tell Claude what to change
|