ratingslib.ratings.rating module
This module provides the RatingMethod
abstract class for rating
systems.
- class RatingSystem(version: str)
Bases:
object
This class represents a Rating method / system. The logic behind class structure is that the rating system can be divided in two phases:
the preparation phase,
preparation_phase()
the computation phase,
computation_phase()
Extend this class and override abstract methods to define a rating system.
Warning: This class should not be used directly. Use derived classes instead.
- Parameters
version (str) – A string that shows the version of rating system. The available versions can be found in
ratingslib.utils.enums.ratings
class.
- score
The score number that represents rating for a single item
- Type
float
- rating
The rating value of items are stored in a numpy array of shape (n,)
where n = the total number of teams- Type
numpy.ndarray
- ord_dict_attr
An order dictionary that maps attributes
- Type
Optional[dict]
- params_key
String representation of parameters. For rating systems without parameters their version is used.
- Type
str
- abstract computation_phase()
To be overridden in subclasses.
- abstract preparation_phase(data_df: DataFrame, items_df: DataFrame, columns_dict: Optional[Dict[str, Any]] = None)
To be overridden in subclasses.
- abstract 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
- rate_from_file(filename: str, pairwise: bool = True, reverse_attributes_cols: Optional[List[str]] = None, sort: bool = False, columns_dict: Optional[Dict[str, Any]] = None) DataFrame
This method computes ratings for a pairwise data. (e.g. soccer teams games). Data are stored in a filename.
- Parameters
filename (str) – The name of file or file path+filename.
sort (bool, default=True) – If
True
, the output is sorted by rating value.pairwise (bool, default=True) – If
True
then data is in pairwise structure.reverse_attributes_cols (Optional[List[str]], default = None) – Name of columns (from csv file) where the numerical scoring scale runs in the opposite direction. Valid only if pairwise is
False
.columns_dict (Optional[Dict[str, str]], default=None) – 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
- set_rating(items_df: DataFrame, rating_lower_best: bool = False, sort: bool = False) DataFrame
Set the rating values and produce items rankings
- Parameters
items_df (pandas.DataFrame) – Set of items (e.g. teams) to be rated
rating_lower_best (bool, default=True) – If
True
then lower rating is better, elseFalse
sort (bool, default=True) – Sort the items by rating value if
True
- Returns
items_df – The set of items with their rating and ranking.
- Return type
pandas.DataFrame
- create_ordered_dict(**kwargs)
- property params_key: str