Syntrex commited on
Commit
3db7ffd
·
verified ·
1 Parent(s): b149c7a

Update models/pitch_model.py

Browse files
Files changed (1) hide show
  1. models/pitch_model.py +22 -0
models/pitch_model.py CHANGED
@@ -64,6 +64,28 @@ def predict_pitch_outcome(
64
  "ball_in_play_prob": float(min(1.0, ball_in_play_prob)),
65
  }
66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  def pitcher_baseline_from_events(df: pd.DataFrame) -> dict[str, float]:
69
  if df.empty:
 
64
  "ball_in_play_prob": float(min(1.0, ball_in_play_prob)),
65
  }
66
 
67
+ def blend_pitch_outcome_probabilities(
68
+ baseline_probs: dict[str, float],
69
+ live_probs: dict[str, float],
70
+ baseline_weight: float,
71
+ live_weight: float,
72
+ ) -> dict[str, float]:
73
+ """
74
+ Blend baseline and live pitch-outcome probabilities at the probability layer.
75
+ This is stronger than only blending raw inputs.
76
+ """
77
+ keys = ["strike_prob", "whiff_prob", "damage_prob", "ball_in_play_prob"]
78
+
79
+ out: dict[str, float] = {}
80
+
81
+ for key in keys:
82
+ base_val = float(baseline_probs.get(key, 0.0) or 0.0)
83
+ live_val = float(live_probs.get(key, base_val) or base_val)
84
+
85
+ blended = (base_val * baseline_weight) + (live_val * live_weight)
86
+ out[key] = float(max(0.0, min(1.0, blended)))
87
+
88
+ return out
89
 
90
  def pitcher_baseline_from_events(df: pd.DataFrame) -> dict[str, float]:
91
  if df.empty: