UFCData 0.7.2__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.2
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(
@@ -355,7 +355,7 @@ data = ufc.get_data()
355
355
  fights_df = data["past_fights"].copy()
356
356
 
357
357
  fights_df["Fighter 1 Probability"] = fights_df["Fighter 1 Odds"].apply(
358
- ufc.convert_odds,
358
+ ufc.convert_odds
359
359
  )
360
360
  ```
361
361
 
@@ -644,12 +644,12 @@ past_fights = past_fights[past_fights[["Fighter 1 Odds", "Fighter 2 Odds"]].notn
644
644
  ## Convert odds to probabilities
645
645
  past_fights["Fighter 1 Probability"] = (
646
646
  past_fights["Fighter 1 Odds"]
647
- .apply(ufc.convert_odds, probability=True)
647
+ .apply(ufc.convert_odds)
648
648
  )
649
649
 
650
650
  past_fights["Fighter 2 Probability"] = (
651
651
  past_fights["Fighter 2 Odds"]
652
- .apply(ufc.convert_odds, probability=True)
652
+ .apply(ufc.convert_odds)
653
653
  )
654
654
 
655
655
  ## Create the data for cross validation and final testing
@@ -700,12 +700,12 @@ future_fights = data["future_fights"].copy()
700
700
 
701
701
  future_fights["Fighter 1 Probability"] = (
702
702
  future_fights["Fighter 1 Odds"]
703
- .apply(ufc.convert_odds, probability=True)
703
+ .apply(ufc.convert_odds)
704
704
  )
705
705
 
706
706
  future_fights["Fighter 2 Probability"] = (
707
707
  future_fights["Fighter 2 Odds"]
708
- .apply(ufc.convert_odds, probability=True)
708
+ .apply(ufc.convert_odds)
709
709
  )
710
710
 
711
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.2
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "UFCData"
7
- version = "0.7.2"
7
+ version = "0.7.3"
8
8
  description = "Obtain UFC data and functions to manipulate it"
9
9
  requires-python = ">=3.10"
10
10
 
@@ -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)
@@ -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,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
File without changes