UFCData 0.7.1__tar.gz → 0.7.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: UFCData
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary: Obtain UFC data and functions to manipulate it
5
5
  Requires-Python: >=3.10
6
6
  License-File: LICENSE.md
@@ -295,7 +295,7 @@ data = ufc.get_data()
295
295
 
296
296
  fighter_bio = data["fighter_bio"].copy()
297
297
  fights_df = data["past_fights"].copy()
298
- rounds_df = data['past_rounds'].copy()
298
+ rounds_df = data['rounds'].copy()
299
299
  future_df = data['future_fights']
300
300
 
301
301
  jon_jones = ufc.search(
@@ -322,16 +322,16 @@ jon_jones_current, jon_jones_past = ufc.get_fighter_statistic(
322
322
  The function `convert_odds()` converts American betting odds from strings into integers or floating point numbers.
323
323
 
324
324
  ```python
325
- convert_odds(odds, probability)
325
+ convert_odds(odds)
326
326
  ```
327
327
 
328
328
  ### Parameters
329
329
 
330
- * `odds` — American betting odds as a string.
330
+ * `odds` — American betting odds as a string, integer, float or None.
331
331
 
332
332
  ### Returns
333
333
 
334
- If probability=True, it returns a `float` representing the implied probability of the betting odds.
334
+ Returns a `float` representing the implied probability of the betting odds.
335
335
 
336
336
  For positive American odds:
337
337
 
@@ -344,7 +344,6 @@ For negative American odds:
344
344
  ```text
345
345
  Probability = -odds / (-odds + 100)
346
346
  ```
347
- If probability=False, takes the string and converts it to an integer.
348
347
 
349
348
  ### Example
350
349
 
@@ -355,13 +354,8 @@ data = ufc.get_data()
355
354
 
356
355
  fights_df = data["past_fights"].copy()
357
356
 
358
- fights_df["Fighter 1 Odds"] = fights_df["Fighter 1 Odds"].apply(
359
- ufc.convert_odds
360
- )
361
-
362
357
  fights_df["Fighter 1 Probability"] = fights_df["Fighter 1 Odds"].apply(
363
- ufc.convert_odds,
364
- probability=True
358
+ ufc.convert_odds
365
359
  )
366
360
  ```
367
361
 
@@ -650,12 +644,12 @@ past_fights = past_fights[past_fights[["Fighter 1 Odds", "Fighter 2 Odds"]].notn
650
644
  ## Convert odds to probabilities
651
645
  past_fights["Fighter 1 Probability"] = (
652
646
  past_fights["Fighter 1 Odds"]
653
- .apply(ufc.convert_odds, probability=True)
647
+ .apply(ufc.convert_odds)
654
648
  )
655
649
 
656
650
  past_fights["Fighter 2 Probability"] = (
657
651
  past_fights["Fighter 2 Odds"]
658
- .apply(ufc.convert_odds, probability=True)
652
+ .apply(ufc.convert_odds)
659
653
  )
660
654
 
661
655
  ## Create the data for cross validation and final testing
@@ -706,12 +700,12 @@ future_fights = data["future_fights"].copy()
706
700
 
707
701
  future_fights["Fighter 1 Probability"] = (
708
702
  future_fights["Fighter 1 Odds"]
709
- .apply(ufc.convert_odds, probability=True)
703
+ .apply(ufc.convert_odds)
710
704
  )
711
705
 
712
706
  future_fights["Fighter 2 Probability"] = (
713
707
  future_fights["Fighter 2 Odds"]
714
- .apply(ufc.convert_odds, probability=True)
708
+ .apply(ufc.convert_odds)
715
709
  )
716
710
 
717
711
  future_fights["Predicted Winner"] = np.where(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: UFCData
3
- Version: 0.7.1
3
+ Version: 0.7.3
4
4
  Summary: Obtain UFC data and functions to manipulate it
5
5
  Requires-Python: >=3.10
6
6
  License-File: LICENSE.md
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=40.8.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "UFCData"
7
+ version = "0.7.3"
8
+ description = "Obtain UFC data and functions to manipulate it"
9
+ requires-python = ">=3.10"
10
+
11
+ dependencies = [
12
+ "huggingface-hub",
13
+ "pandas",
14
+ "numpy",
15
+ "glicko2",
16
+ "rapidfuzz",
17
+ "matplotlib",
18
+ ]
19
+
20
+ [tool.setuptools.packages.find]
21
+ include = ["ufcdata*"]
22
+ exclude = ["scraper*", "UFCData_backup*"]
@@ -694,4 +694,4 @@ def get_fighter_statistic(fighter_link, fighter_bio, fights_df, rounds_df,
694
694
  current_statistic["Date"] = np.nan
695
695
  past_statistic = statistic.iloc[1:].reset_index(drop=True)
696
696
 
697
- return (current_statistic, past_statistic)
697
+ return (current_statistic, past_statistic)
@@ -2,9 +2,9 @@ import re
2
2
  import pandas as pd
3
3
  import numpy as np
4
4
 
5
- def convert_odds(odds, probability=False):
5
+ def convert_odds(odds):
6
6
  """
7
- Convert American betting odds to a numeric value or implied probability.
7
+ Convert American betting odds to implied probability.
8
8
 
9
9
  Parameters
10
10
  ----------
@@ -12,23 +12,16 @@ def convert_odds(odds, probability=False):
12
12
  American betting odds. The function extracts the first signed or
13
13
  unsigned integer from the input. Missing values return None.
14
14
 
15
- probability : bool, default=False
16
- If False, return the extracted American odds as an integer.
17
- If True, return the implied probability as a decimal.
18
-
19
15
  Returns
20
16
  -------
21
- int or float or None
22
- The extracted American odds if probability=False, otherwise the
23
- implied probability. Returns None for missing values.
17
+ float or None
18
+ The implied probability as a decimal. Returns None for missing values.
24
19
 
25
20
  Examples
26
21
  --------
27
22
  >>> convert_odds("+120")
28
- 120
23
+ 0.45454545454545453
29
24
  >>> convert_odds("-400")
30
- -400
31
- >>> convert_odds("-400", probability=True)
32
25
  0.8
33
26
  """
34
27
  if pd.isna(odds):
@@ -36,9 +29,6 @@ def convert_odds(odds, probability=False):
36
29
 
37
30
  odds = int(re.search(r'[+-]?\d+', str(odds)).group())
38
31
 
39
- if not probability:
40
- return odds
41
-
42
32
  if odds < 0:
43
33
  return -odds / (-odds + 100)
44
34
  else:
@@ -1,5 +1,4 @@
1
1
  import pandas as pd
2
- from glicko2 import Player
3
2
 
4
3
  #@title Elo function
5
4
  def expected_score(rating, opponent_rating, s):
@@ -11,7 +10,7 @@ def update_rating(rating, k, outcome, expected):
11
10
 
12
11
  # Elo function
13
12
  # Make sure fights are sorted from most recent to least recent. Gets Elo prior to fight.
14
- def get_elo(fight_df, fighter_df, r=1500, k=30, s=400):
13
+ def get_elo(r=1500, k=30, s=400):
15
14
  """
16
15
  Calculates pre-fight Elo ratings for UFC fighters.
17
16
 
@@ -22,13 +21,6 @@ def get_elo(fight_df, fighter_df, r=1500, k=30, s=400):
22
21
 
23
22
  Parameters
24
23
  ----------
25
- fight_df : pandas.DataFrame
26
- UFC fight data sorted from most recent to least recent.
27
- Must contain fighter links, fight outcomes, and the fight
28
- information required to construct the output.
29
- fighter_df : pandas.DataFrame
30
- DataFrame containing fighter information. Must contain a
31
- "Fighter Link" column used to identify each fighter.
32
24
  r : float, default=1500
33
25
  Initial Elo rating assigned to each fighter.
34
26
  k : float, default=30
@@ -47,20 +39,25 @@ def get_elo(fight_df, fighter_df, r=1500, k=30, s=400):
47
39
  Fight-level DataFrame containing the original fight information
48
40
  and the Elo rating of each fighter immediately before the fight.
49
41
 
50
- Notes
51
- -----
52
- The input fight data should be sorted from most recent to least
53
- recent. The function reverses this order internally to process
54
- fights chronologically, then returns the resulting data in the
55
- original order.
56
-
57
42
  Examples
58
43
  --------
59
- >>> fighter_elo, fight_elo = get_elo(fight_df, fighter_df)
44
+ >>> fighter_elo, fight_elo = get_elo(1000, 10, 20)
60
45
  >>> fight_elo[["Fighter 1", "Fighter 1 Elo",
61
46
  ... "Fighter 2", "Fighter 2 Elo"]].head()
62
47
  """
63
48
 
49
+
50
+ past_fights = (
51
+ f"https://huggingface.co/datasets/JunoML/MMA/resolve/main/"
52
+ f"past_fights.csv"
53
+ )
54
+
55
+ fighter_bio = (
56
+ f"https://huggingface.co/datasets/JunoML/MMA/resolve/main/"
57
+ f"fighter_bio.csv"
58
+ )
59
+
60
+ fight_df = pd.read_csv(past_fights)
64
61
  fight_df = fight_df[::-1]
65
62
 
66
63
  original_fight_df = fight_df.copy()
@@ -69,12 +66,14 @@ def get_elo(fight_df, fighter_df, r=1500, k=30, s=400):
69
66
  fighter_2_elo = []
70
67
 
71
68
  ## Create a dictionary of fighters and their Elo
69
+ fighter_df = pd.read_csv(fighter_bio)
72
70
  fighter_df = fighter_df.copy()
73
71
  fighter_df["Elo"] = r
74
72
  fighter_df = dict(zip(fighter_df["Fighter Link"], fighter_df["Elo"]))
75
73
 
76
74
  ## Create a list of fights
77
- fight_df = fight_df[["Fighter 1 Link", "Fighter 1 Outcome", "Fighter 2 Link", "Fighter 2 Outcome"]]
75
+ fight_df = fight_df[["Fighter 1 Link", "Fighter 1 Outcome",
76
+ "Fighter 2 Link", "Fighter 2 Outcome"]]
78
77
  fight_df = fight_df.values.tolist()
79
78
 
80
79
 
@@ -120,11 +119,15 @@ def get_elo(fight_df, fighter_df, r=1500, k=30, s=400):
120
119
  ],
121
120
  axis=1
122
121
  )
123
- elo = elo[['Date', 'Event Link', 'Fight Number', 'Fight Link', 'Weight Class',
124
- 'Gender', 'Title', 'Fighter 1', 'Fighter 1 Elo', 'Fighter 1 Odds', 'Fighter 1 Link',
125
- 'Fighter 1 Outcome', 'Fighter 1 Bonus', 'Fighter 2','Fighter 2 Elo', 'Fighter 2 Odds',
126
- 'Fighter 2 Link', 'Fighter 2 Outcome', 'Fighter 2 Bonus', 'Method',
127
- 'Round', 'Time', 'Time Format', 'Referee', 'Details']]
122
+ elo = elo[['Date', 'Event Link', 'Fight Number',
123
+ 'Fight Link', 'Weight Class', 'Gender',
124
+ 'Title', 'Fighter 1', 'Fighter 1 Elo',
125
+ 'Fighter 1 Odds', 'Fighter 1 Link',
126
+ 'Fighter 1 Outcome', 'Fighter 1 Bonus',
127
+ 'Fighter 2','Fighter 2 Elo', 'Fighter 2 Odds',
128
+ 'Fighter 2 Link', 'Fighter 2 Outcome',
129
+ 'Fighter 2 Bonus', 'Method', 'Round', 'Time',
130
+ 'Time Format', 'Referee', 'Details']]
128
131
  past_elo = elo[::-1].copy()
129
132
  current_elo = fighter_df
130
- return (current_elo, past_elo)
133
+ return (current_elo, past_elo)
@@ -0,0 +1,46 @@
1
+ from rapidfuzz.fuzz import ratio
2
+ import pandas as pd
3
+
4
+ def search(data, column , query, matches=1):
5
+ """
6
+ Searches a UFC dataset for rows matching a query.
7
+
8
+ The dataset is loaded as a CSV file from the JunoML/MMA Hugging Face
9
+ repository. Fuzzy string matching is used to identify the rows in the
10
+ specified column that most closely match the query.
11
+
12
+ Parameters
13
+ ----------
14
+ data : str
15
+ Name of the CSV dataset to search, without the .csv extension.
16
+ For example, "fighter_bio".
17
+ column : str
18
+ Name of the column to search.
19
+ query : str
20
+ Search query to match against the specified column.
21
+ matches : int, default=1
22
+ Number of closest matches to return.
23
+
24
+ Returns
25
+ -------
26
+ pandas.DataFrame
27
+ DataFrame containing the closest matching rows, sorted from
28
+ highest to lowest similarity. The index is reset.
29
+
30
+ Examples
31
+ --------
32
+ >>> results = search("fighter_bio", "Name", "John Jones", 1)
33
+ >>> print(results)
34
+ """
35
+
36
+ url = f"https://huggingface.co/datasets/JunoML/MMA/resolve/main/{data}.csv"
37
+ df = pd.read_csv(url)
38
+
39
+ scores = df[column].fillna("").apply(
40
+ lambda x: ratio(str(x), query))
41
+
42
+ result = df.loc[scores.nlargest(matches).index].copy()
43
+ result["score"] = scores.loc[result.index]
44
+ result = result.sort_values("score", ascending=False).drop(columns="score")
45
+
46
+ return result.reset_index(drop=True)
@@ -1,14 +0,0 @@
1
- [project]
2
- name = "UFCData"
3
- version = "0.7.1"
4
- description = "Obtain UFC data and functions to manipulate it"
5
- requires-python = ">=3.10"
6
-
7
- dependencies = [
8
- "huggingface-hub",
9
- "pandas",
10
- "numpy",
11
- "glicko2",
12
- "rapidfuzz",
13
- "matplotlib",
14
- ]
@@ -1,39 +0,0 @@
1
- from rapidfuzz.fuzz import ratio
2
-
3
- def search(data, column , query, matches=1):
4
- """
5
- Searches a UFC DataFrame for rows matching a query.
6
-
7
- Uses fuzzy string matching to identify the rows in the specified
8
- column that most closely match the query.
9
-
10
- Parameters
11
- ----------
12
- data : pandas.DataFrame
13
- UFC DataFrame to search.
14
- column : str
15
- Name of the column to search.
16
- query : str
17
- Search query to match against the specified column.
18
- matches : int, default=1
19
- Number of closest matches to return.
20
-
21
- Returns
22
- -------
23
- pandas.DataFrame
24
- DataFrame containing the closest matching rows, sorted from
25
- highest to lowest similarity.
26
-
27
- Examples
28
- --------
29
- >>> data = get_data()
30
- >>> results = search(data["fighters"], "Name", "Jon Jones")
31
- """
32
- scores = data[column].fillna("").apply(
33
- lambda x: ratio(str(x), query))
34
-
35
- result = data.loc[scores.nlargest(matches).index].copy()
36
- result["score"] = scores.loc[result.index]
37
- result = result.sort_values("score", ascending=False).drop(columns="score")
38
-
39
- return result
File without changes
File without changes
File without changes
File without changes
File without changes