ratingslib.ratings.winloss module
WinLoss Rating System
- class Winloss(version=ratings.WINLOSS, normalization=True)
Bases:
RatingSystem
The traditional rating method which is popular in the field of sports. In the case of sports teams the method takes into account the total wins of each team. The first-ranked team is the team with the most wins. Note that for any kind of items, there are many ways to define the notion of a hypothetical matchup and then to determine scores and winners.
- Parameters
version (str, default=ratings.WINLOSS) – A string that shows the version of rating system. The available versions can be found in
ratingslib.utils.enums.ratings
class.normalization (bool, default = True) – If
True
then the result will be normalized according to the total times each item occurs in the dataset. For example in sport teams set normalization =True
if the teams haven’t played same number of games. This means that each element of W vector is divided by the total number of games played by the respective team.
- W
The WinLoss vector for items of shape (n,) where n = the total number of items. Each element of vector represents the total wins of the respective item.
- Type
numpy.ndarray
Examples
The following example demonstrates Winloss rating system, for the 20 first soccer matches that took place during the 2018-2019 season of English Premier League.
>>> from ratingslib.datasets.filenames import dataset_path, FILENAME_EPL_2018_2019_20_GAMES >>> from ratingslib.ratings.winloss import Winloss >>> filename = dataset_path(FILENAME_EPL_2018_2019_20_GAMES) >>> Winloss(normalization=False).rate_from_file(filename) Item rating ranking 0 Arsenal 0.0 3 1 Bournemouth 2.0 1 2 Brighton 1.0 2 3 Burnley 0.0 3 4 Cardiff 0.0 3 5 Chelsea 2.0 1 6 Crystal Palace 1.0 2 7 Everton 1.0 2 8 Fulham 0.0 3 9 Huddersfield 0.0 3 10 Leicester 1.0 2 11 Liverpool 2.0 1 12 Man City 2.0 1 13 Man United 1.0 2 14 Newcastle 0.0 3 15 Southampton 0.0 3 16 Tottenham 2.0 1 17 Watford 2.0 1 18 West Ham 0.0 3 19 Wolves 0.0 3
- computation_phase()
All the calculations are made in
ratingslib.ratings.winloss.Winloss.create_win_loss_vector()
method. Winloss vector is the rating vector.
- create_win_loss_vector(data_df: DataFrame, items_df: DataFrame, columns_dict: Optional[Dict[str, Any]] = None) ndarray
Construction of WinLoss vector.
- preparation_phase(data_df: DataFrame, items_df: DataFrame, columns_dict: Optional[Dict[str, Any]] = None)
To be overridden in subclasses.
- rate(data_df: DataFrame, items_df: DataFrame, sort: bool = False, columns_dict: Optional[Dict[str, Any]] = None) DataFrame
This method computes ratings for a pairwise data. (e.g. soccer teams games). To be overridden in subclasses.
- Parameters
data_df (pandas.DataFrame) – The pairwise data.
items_df (pandas.DataFrame) – Set of items (e.g. teams) to be rated
sort (bool, default=True.) – If true, the output is sorted by rating value
columns_dict (Optional[Dict[str, str]]) – The column names of data file. See
ratingslib.datasets.parameters.COLUMNS_DICT
for more details.
- Returns
items_df – The set of items with their rating and ranking.
- Return type
pandas.DataFrame