Rating class¶
Class for all rating related things.
-
class
pyanp.rating.
Rating
[source]¶ Represents rating a full group of alternatives for a group of users. The data is essentially a dataframe and a WordEval object to evaluate that to scores.
-
add_alt
(alt_name, ignore_existing=True)[source]¶ Adds an alternative/s, by name
Parameters: - alt_name – A str name, or a list of names to add.
- ignore_existing – If True and we try to add an existing alternative we simply skip by, otherwise we throw an error.
Returns: Nothing
-
add_user
(uname)[source]¶ Adds one or more uses to this system.
Parameters: uname – The str name of the user to add, or a list of str names of users to add. Returns: Nothing
-
alt_names
()[source]¶ Returns: A list of str alternative names in this system. Ordered as the data in the ratings votes are ordered (columns).
-
is_alt
(alt: str) → bool[source]¶ Tells if the item is an alternative
Parameters: alt – The name of the alternative to check for. Returns: True/False
-
is_user
(uname: str)[source]¶ Parameters: uname – The name of the user to check for Returns: True/False if the given user exists in the system.
-
priority
(username=None, ptype: pyanp.prioritizer.PriorityType = None)[source]¶ Calculates the alternative priority for the specified user/users and the given normalizer type.
Parameters: - username – The name (this of names) of the user (users) to get the overall priority of. If None, then we return the total group average.
- ptype – How should we normalize?
Returns: A pandas.Series whose index is self.alt_names() and whose values are the priorities.
-
set_word_eval
(param)[source]¶ Sets the WordEval object
Parameters: param – This could either be a WordEval object, or a something that WordEval(param) would work with Returns: None
-
user_names
()[source]¶ Returns: A list of str names of users in this system. Ordered as the data in the ratings votes are ordered (the rows).
-
vote_column
(alt_name, votes, createUnknownUsers=True)[source]¶ Specifies all votes (across all users) for a specific alternative.
Parameters: - alt_name – The name of the alternative to set the data for
- votes – Should either be a list with self.nusers() items, or a pandas.Series or dict with usernames as index.
- createUnknownUsers – If True and unknown users appear in the index of votes, we will create those users before trying to do the assignment.
Returns: Nothing
-
vote_values
(username=None, alt_name=None)[source]¶ Gets the numeric vote values for the given user/alternative (or whole column or dataframe).
Parameters: - username – If None, we get the values for all users. If a list get the values for each user in the list, or it could just be a single username.
- alt_name – Either None, meaing get it for all alternatives, or a single alternative name (to get one column).
Returns: If username=None and alt_name=None, returns a pandas.DataFrame of the numeric values. Otherwise returns a pandas.Series of values as the result.
-
-
class
pyanp.rating.
WordEval
(vals)[source]¶ Information for a Word Evaluator, i.e. a function that inputs a word and outputs a numeric value.
-
eval
(word)[source]¶ Evaluates a word, or a pandas.Series of words.
Parameters: word – The string word to evaluate to a number, or a pandas.Series of data. Returns: The float value if we can evaluate, or None if a single value is passed in. If the word was actually a pandas.Series, we return a pandas.Series with the same index.
-
get_key
(word)[source]¶ Find the key word for this word. A WordEval has a list of words that represent different levels/numerical values. Those words are called keys. In addition, each key has a list of synonyms. For instance the keyword “high” might have a synonym “hi” or “h”. In that case get_key(“hi”) would return “high”.
Parameters: word – The word to look up a synonym for. Returns: The key if this word is a key or a synonym. If it is not a synonym or key, we return None.
-
keys_match_score
(word_list)[source]¶ This function tells us how well this WordEval interprets a list of words. It is used for searhcing through the “standard list” of words to find the best match for a data set.
Parameters: word_list – The list-like of words to see how we can match. Returns: A score <= 1. A positive number means no missing words, i.e. every word in word_list has a value in this WordEval object. The larger number means our word_list uses more of the names in this WordEval object.
-
-
pyanp.rating.
best_std_word_evaluator
(list_of_words, return_name=True)[source]¶ Finds the WordEval in STD_WORD_EVALUATOR that best matches the list of words
Parameters: - list_of_words – The list of words to look for best matches of
- return_name – Should we return the best WordEval or its name in the STD_WORD_EVALUATOR.
Returns: The name of the best match, or the best match WordEval