Syntrex commited on
Commit
15cc068
·
verified ·
1 Parent(s): c151fc1

Update models/pitch_sequence_model.py

Browse files
Files changed (1) hide show
  1. models/pitch_sequence_model.py +36 -2
models/pitch_sequence_model.py CHANGED
@@ -93,8 +93,8 @@ def _normalize_probs(fastball_prob: float, breaking_prob: float, offspeed_prob:
93
 
94
  def predict_next_pitch_distribution(feature_row: dict[str, Any]) -> dict[str, Any]:
95
  """
96
- Pitch sequencing model v2.
97
- Still coarse, but now count-aware and sequence-aware.
98
  """
99
  balls = int(feature_row.get("balls", 0))
100
  strikes = int(feature_row.get("strikes", 0))
@@ -105,6 +105,10 @@ def predict_next_pitch_distribution(feature_row: dict[str, Any]) -> dict[str, An
105
  batter_barrel_rate = feature_row.get("batter_barrel_rate")
106
  batter_hard_hit_rate = feature_row.get("batter_hard_hit_rate")
107
 
 
 
 
 
108
  fastball_prob = 0.48
109
  breaking_prob = 0.32
110
  offspeed_prob = 0.20
@@ -157,6 +161,36 @@ def predict_next_pitch_distribution(feature_row: dict[str, Any]) -> dict[str, An
157
  except Exception:
158
  pass
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  fastball_prob, breaking_prob, offspeed_prob = _normalize_probs(
161
  fastball_prob, breaking_prob, offspeed_prob
162
  )
 
93
 
94
  def predict_next_pitch_distribution(feature_row: dict[str, Any]) -> dict[str, Any]:
95
  """
96
+ Pitch sequencing model v2.1
97
+ Count-aware, sequence-aware, and lightly live-telemetry-aware.
98
  """
99
  balls = int(feature_row.get("balls", 0))
100
  strikes = int(feature_row.get("strikes", 0))
 
105
  batter_barrel_rate = feature_row.get("batter_barrel_rate")
106
  batter_hard_hit_rate = feature_row.get("batter_hard_hit_rate")
107
 
108
+ velo_delta = feature_row.get("velo_delta_from_baseline")
109
+ spin_delta = feature_row.get("spin_delta_from_baseline")
110
+ extension_delta = feature_row.get("extension_delta_from_baseline")
111
+
112
  fastball_prob = 0.48
113
  breaking_prob = 0.32
114
  offspeed_prob = 0.20
 
161
  except Exception:
162
  pass
163
 
164
+ # Live overlay: if velo is down, reduce fastball confidence slightly
165
+ try:
166
+ if velo_delta is not None and float(velo_delta) <= -1.0:
167
+ fastball_prob -= 0.03
168
+ breaking_prob += 0.02
169
+ offspeed_prob += 0.01
170
+ elif velo_delta is not None and float(velo_delta) >= 1.0:
171
+ fastball_prob += 0.02
172
+ breaking_prob -= 0.01
173
+ offspeed_prob -= 0.01
174
+ except Exception:
175
+ pass
176
+
177
+ # Live overlay: if spin is down, slightly reduce breaking-ball trust
178
+ try:
179
+ if spin_delta is not None and float(spin_delta) <= -120:
180
+ breaking_prob -= 0.02
181
+ fastball_prob += 0.01
182
+ offspeed_prob += 0.01
183
+ except Exception:
184
+ pass
185
+
186
+ # Live overlay: shorter extension can imply less deception
187
+ try:
188
+ if extension_delta is not None and float(extension_delta) <= -0.25:
189
+ fastball_prob -= 0.01
190
+ offspeed_prob += 0.01
191
+ except Exception:
192
+ pass
193
+
194
  fastball_prob, breaking_prob, offspeed_prob = _normalize_probs(
195
  fastball_prob, breaking_prob, offspeed_prob
196
  )