UFCData 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ufcdata-0.3.0 → ufcdata-0.4.0}/PKG-INFO +1 -1
- {ufcdata-0.3.0 → ufcdata-0.4.0}/README.md +166 -3
- {ufcdata-0.3.0 → ufcdata-0.4.0}/UFCData.egg-info/PKG-INFO +1 -1
- {ufcdata-0.3.0 → ufcdata-0.4.0}/pyproject.toml +1 -1
- {ufcdata-0.3.0 → ufcdata-0.4.0}/ufcdata/fighter.py +3 -7
- {ufcdata-0.3.0 → ufcdata-0.4.0}/LICENSE.md +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/UFCData.egg-info/SOURCES.txt +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/UFCData.egg-info/dependency_links.txt +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/UFCData.egg-info/requires.txt +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/UFCData.egg-info/top_level.txt +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/setup.cfg +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/ufcdata/__init__.py +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/ufcdata/data.py +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/ufcdata/ratings.py +0 -0
- {ufcdata-0.3.0 → ufcdata-0.4.0}/ufcdata/search.py +0 -0
|
@@ -18,8 +18,8 @@ Rating Function
|
|
|
18
18
|
- [Elo](#elo)
|
|
19
19
|
|
|
20
20
|
Fighter Functions
|
|
21
|
-
- [Fighter History](#
|
|
22
|
-
- [Fighter Statistic](#
|
|
21
|
+
- [Fighter History](#fighter-history)
|
|
22
|
+
- [Fighter Statistic](#fighter-statistics)
|
|
23
23
|
|
|
24
24
|
Helper Functions
|
|
25
25
|
- [Odds Convert](#elo)
|
|
@@ -144,7 +144,7 @@ The resulting `fight_elo` dataframe can then be used to examine or incorporate p
|
|
|
144
144
|
|
|
145
145
|
## Fighter History
|
|
146
146
|
|
|
147
|
-
The `get_fighter_history()`
|
|
147
|
+
The function `get_fighter_history()` retrieves all UFC fights for a specific fighter and formats the results from the fighter's perspective. The requested fighter is always represented as `"Fighter 1"`, regardless of which side of the original fight dataframe they appeared on.
|
|
148
148
|
|
|
149
149
|
The function also calculates the age of both fighters at the time of each fight and assigns a `"UFC Fight"` number to each fight.
|
|
150
150
|
|
|
@@ -192,6 +192,169 @@ jon_jones_history = ufc.get_fighter_history(
|
|
|
192
192
|
|
|
193
193
|
This function is useful for analyzing an individual fighter's career, constructing fighter-level features, or preparing historical data for predictive modeling.
|
|
194
194
|
|
|
195
|
+
## Fighter Statistics
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
The function `get_fighter_statistic()`, transforms a fighter's UFC fight history into a time-series dataset where each row represents the fighter's statistics **as they were known before a particular fight**.
|
|
199
|
+
|
|
200
|
+
This is designed for machine-learning applications where using information from the future would cause data leakage.
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
get_fighter_statistic(
|
|
205
|
+
fighter_link,
|
|
206
|
+
fighter_bio,
|
|
207
|
+
fights_df,
|
|
208
|
+
rounds_df,
|
|
209
|
+
r=1500,
|
|
210
|
+
k=30,
|
|
211
|
+
s=400
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
### Parameters
|
|
218
|
+
|
|
219
|
+
| Parameter | Type | Description |
|
|
220
|
+
| -------------- | ----------------------- | -------------------------------------------------------------------------------------------------- |
|
|
221
|
+
| `fighter_link` | `str` | UFCStats link or identifier for the fighter. |
|
|
222
|
+
| `fighter_bio` | `pd.DataFrame` | Fighter biography DataFrame containing fighter names and links. |
|
|
223
|
+
| `fights_df` | `pd.DataFrame` | Fight-level UFC data containing fight results and metadata. |
|
|
224
|
+
| `rounds_df` | `pd.DataFrame` | Round-level UFC statistics. |
|
|
225
|
+
| `future_df` | `pd.DataFrame` | DataFrame containing the upcoming fight. The first row is used to determine the future fight date. |
|
|
226
|
+
| `r` | `float`, default `1500` | Initial Elo rating. |
|
|
227
|
+
| `k` | `float`, default `30` | Elo K-factor controlling the magnitude of rating updates. |
|
|
228
|
+
| `s` | `float`, default `400` | Elo scaling factor used when calculating expected scores. |
|
|
229
|
+
|
|
230
|
+
### Returns
|
|
231
|
+
|
|
232
|
+
The function returns two DataFrames:
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
current_statistic, past_statistic = get_fighter_statistic(...)
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
#### `current_statistic`
|
|
239
|
+
|
|
240
|
+
A one-row DataFrame containing the fighter's current statistic.
|
|
241
|
+
|
|
242
|
+
This includes:
|
|
243
|
+
|
|
244
|
+
* UFC fight number
|
|
245
|
+
* UFC record
|
|
246
|
+
* UFC win rate
|
|
247
|
+
* Elo rating
|
|
248
|
+
* Cumulative fight time
|
|
249
|
+
* Significant strikes landed per minute (`SLpM`)
|
|
250
|
+
* Significant strike accuracy (`Str Acc`)
|
|
251
|
+
* Significant strikes absorbed per minute (`SApM`)
|
|
252
|
+
* Significant strike defense (`Str Def`)
|
|
253
|
+
* Takedown average (`TD Avg`)
|
|
254
|
+
* Takedown accuracy (`TD Acc`)
|
|
255
|
+
* Takedown defense (`TD Def`)
|
|
256
|
+
* Submission attempts per 15 minutes (`Sub Avg`)
|
|
257
|
+
|
|
258
|
+
#### `past_statistic`
|
|
259
|
+
|
|
260
|
+
A DataFrame containing the same types of statistics for each previous UFC fight.
|
|
261
|
+
|
|
262
|
+
Each row represents the fighter's information **immediately before that fight**.
|
|
263
|
+
|
|
264
|
+
For example:
|
|
265
|
+
|
|
266
|
+
```text
|
|
267
|
+
Fight 1 → statistics before Fight 1
|
|
268
|
+
Fight 2 → statistics before Fight 2
|
|
269
|
+
Fight 3 → statistics before Fight 3
|
|
270
|
+
...
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
This makes the data suitable for constructing historical features for a predictive model.
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
### Example
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
current_statistic, past_statistic = get_fighter_statistic(
|
|
280
|
+
fighter_link=fighter_link,
|
|
281
|
+
fighter_bio=fighter_bio,
|
|
282
|
+
fights_df=fights_df,
|
|
283
|
+
rounds_df=rounds_df,
|
|
284
|
+
)
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
## Data Requirements
|
|
289
|
+
|
|
290
|
+
The function expects the input DataFrames to contain the relevant fighter, fight, and round-level information.
|
|
291
|
+
|
|
292
|
+
### `fighter_bio`
|
|
293
|
+
|
|
294
|
+
Must contain at least:
|
|
295
|
+
|
|
296
|
+
```text
|
|
297
|
+
Name
|
|
298
|
+
Fighter Link
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### `fights_df`
|
|
302
|
+
|
|
303
|
+
Must contain fighter links, outcomes, fight dates, and fight metadata required by the function.
|
|
304
|
+
|
|
305
|
+
### `rounds_df`
|
|
306
|
+
|
|
307
|
+
Must contain round-level striking, takedown, submission, and control statistics.
|
|
308
|
+
|
|
309
|
+
### `future_df`
|
|
310
|
+
|
|
311
|
+
Must contain:
|
|
312
|
+
|
|
313
|
+
```text
|
|
314
|
+
Date
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
The first row is used to determine the date of the upcoming fight.
|
|
318
|
+
|
|
319
|
+
## Design
|
|
320
|
+
|
|
321
|
+
The function follows this general pipeline:
|
|
322
|
+
|
|
323
|
+
```text
|
|
324
|
+
Fighter
|
|
325
|
+
│
|
|
326
|
+
▼
|
|
327
|
+
Retrieve fight history
|
|
328
|
+
│
|
|
329
|
+
▼
|
|
330
|
+
Construct chronological fight history
|
|
331
|
+
│
|
|
332
|
+
▼
|
|
333
|
+
Calculate UFC record
|
|
334
|
+
│
|
|
335
|
+
▼
|
|
336
|
+
Calculate Elo ratings
|
|
337
|
+
│
|
|
338
|
+
▼
|
|
339
|
+
Calculate cumulative fight statistics
|
|
340
|
+
│
|
|
341
|
+
├── Striking
|
|
342
|
+
├── Takedowns
|
|
343
|
+
└── Submissions
|
|
344
|
+
│
|
|
345
|
+
▼
|
|
346
|
+
Generate pre-fight statistics
|
|
347
|
+
│
|
|
348
|
+
├── Past fights
|
|
349
|
+
└── Upcoming fight
|
|
350
|
+
│
|
|
351
|
+
▼
|
|
352
|
+
Return current_statistic, past_statistic
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
The resulting data can then be combined with opponent statistics and other fight-level features to create inputs for UFC fight prediction models.
|
|
356
|
+
|
|
357
|
+
|
|
195
358
|
|
|
196
359
|
## Online Sources
|
|
197
360
|
|
|
@@ -112,7 +112,7 @@ def get_fighter_history(fighter_link, fighter_bio, fights_df):
|
|
|
112
112
|
|
|
113
113
|
|
|
114
114
|
|
|
115
|
-
def get_fighter_statistic(fighter_link, fighter_bio, fights_df, rounds_df,
|
|
115
|
+
def get_fighter_statistic(fighter_link, fighter_bio, fights_df, rounds_df,
|
|
116
116
|
r=1500, k=30, s=400):
|
|
117
117
|
|
|
118
118
|
"""
|
|
@@ -140,10 +140,6 @@ def get_fighter_statistic(fighter_link, fighter_bio, fights_df, rounds_df, futur
|
|
|
140
140
|
DataFrame containing UFC fight-level results.
|
|
141
141
|
rounds_df : pandas.DataFrame
|
|
142
142
|
DataFrame containing round-level UFC statistics.
|
|
143
|
-
future_df : pandas.DataFrame
|
|
144
|
-
DataFrame containing the fighter's upcoming fight. The first row
|
|
145
|
-
is used to determine the date for which current statistics are
|
|
146
|
-
calculated.
|
|
147
143
|
r : float, default=1500
|
|
148
144
|
Initial Elo rating assigned to fighters with no previous Elo history.
|
|
149
145
|
k : float, default=30
|
|
@@ -185,8 +181,7 @@ def get_fighter_statistic(fighter_link, fighter_bio, fights_df, rounds_df, futur
|
|
|
185
181
|
|
|
186
182
|
record = get_fighter_history(fighter_link, fighter_bio, fights_df)
|
|
187
183
|
|
|
188
|
-
date =
|
|
189
|
-
date = pd.to_datetime(date).date()
|
|
184
|
+
date = ("2001-01-01")
|
|
190
185
|
|
|
191
186
|
if len(record) == 0:
|
|
192
187
|
columns = [
|
|
@@ -234,6 +229,7 @@ def get_fighter_statistic(fighter_link, fighter_bio, fights_df, rounds_df, futur
|
|
|
234
229
|
df[["UFC W", "UFC L", "UFC D", "UFC NC"]] = (
|
|
235
230
|
df[["UFC W", "UFC L", "UFC D", "UFC NC"]].astype("Int64")
|
|
236
231
|
)
|
|
232
|
+
df.iloc[0, 0] = np.nan
|
|
237
233
|
|
|
238
234
|
return (df, df)
|
|
239
235
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|