File size: 1,171 Bytes
09464ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from __future__ import annotations


def estimate_win_probability(
    score_diff: int,
    inning: int,
    outs: int,
    runner_on_1b: bool,
    runner_on_2b: bool,
    runner_on_3b: bool,
    batting_team_is_home: bool,
) -> tuple[float, float]:
    """
    Simple explainable baseline win probability model.
    Returns away_wp, home_wp.
    """
    base = 0.50

    # score differential is from away team perspective
    base += score_diff * 0.08

    # later innings matter more
    leverage = min(0.18, max(0.0, (inning - 1) * 0.02))
    if score_diff > 0:
        base += leverage
    elif score_diff < 0:
        base -= leverage

    # base/out pressure
    runner_pressure = 0.0
    runner_pressure += 0.03 if runner_on_1b else 0.0
    runner_pressure += 0.05 if runner_on_2b else 0.0
    runner_pressure += 0.07 if runner_on_3b else 0.0
    out_penalty = outs * 0.03

    if batting_team_is_home:
        base -= runner_pressure
        base += out_penalty * 0.3
    else:
        base += runner_pressure
        base -= out_penalty * 0.3

    away_wp = max(0.01, min(0.99, base))
    home_wp = max(0.01, min(0.99, 1.0 - away_wp))
    return away_wp, home_wp