ratingslib.ratings.od module

Offense-Defense rating system

class OffenseDefense(version=ratings.OD, tol=0.0001)

Bases: RatingSystem

Offense-Defense is a modified version of ranking algorithm HITS used in Ask search engine. This rating system developed by Anjela Govan during her PhD 1 2 for sport teams rating. The main idea of this method is to separate the offensive and defensive strength of each team and the final rating vector can be generated by combining offensive and defensive lists.

Parameters
  • version (str, default=ratings.OD) – A string that shows the version of rating system. The available versions can be found in ratingslib.utils.enums.ratings class.

  • tol (float, default=0.0001) – Tolerance level

A

Adjacency matrix of items scores.

Type

numpy.ndarray

P

P matrix of OD method.

Type

numpy.ndarray

defense

Defense rating vector.

Type

numpy.ndarray

offense

Offense rating vector.

Type

numpy.ndarray

error

Error until convergence.

Type

float

iter

Number of iterations to produce convergence of both of the Offense and Defense vectors.

Type

int

References

1

Govan, A. Y., Langville, A. N., & Meyer, C. D. (2009). Offense-defense approach to ranking team sports. Journal of Quantitative Analysis in Sports, 5(1)

2

Govan, A. Y. (2008). Ranking Theory with Application to Popular Sports. Ph.D. dissertation, North Carolina State University.

Examples

The following example demonstrates Offense-Defense 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.od import OffenseDefense
>>> filename = dataset_path(FILENAME_EPL_2018_2019_20_GAMES)
>>> OffenseDefense(tol=0.0001).rate_from_file(filename)
              Item        rating  ranking
0          Arsenal  1.934298e+00       12
1      Bournemouth  1.312759e+06        3
2         Brighton  3.712401e+00       11
3          Burnley  4.103263e+05        4
4          Cardiff  4.757391e-04       14
5          Chelsea  4.576599e+00       10
6   Crystal Palace  1.049852e+03        7
7          Everton  2.080318e-07       16
8           Fulham  1.532621e-12       20
9     Huddersfield  5.583941e-01       13
10       Leicester  1.876215e+04        6
11       Liverpool  3.403605e+12        1
12        Man City  5.284698e+00        9
13      Man United  6.223487e+00        8
14       Newcastle  9.071493e-08       18
15     Southampton  2.510896e-07       15
16       Tottenham  9.071797e-08       17
17         Watford  1.864760e+06        2
18        West Ham  2.311787e+05        5
19          Wolves  3.793810e-11       19
computation_phase()

Compute offense, defense vectors and overall ratings.

create_score_matrices(data_df: DataFrame, items_df: DataFrame, columns_dict: Optional[Dict[str, Any]] = None) Tuple[ndarray, ndarray]

Construct score matrix A and P

preparation_phase(data_df: DataFrame, items_df: DataFrame, columns_dict: Optional[Dict[str, Any]] = None)

Create A and P matrices

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