Elicitation¶
pypbl.elicitation¶
Core module for preference based learning.
-
class
pypbl.elicitation.
BayesPreference
(data, normalise=True)¶ Class for preference based learning using Bayesian inference
Parameters: - data (object) – Pandas DataFrame with columns as features and index as item names
- normalise (bool) – Normalise data using unit normalisation
-
add_indifferent_preference
(a, b)¶ Adds a preference based on a == b
Parameters: - a (str) – name of item a that has equal preference to item b
- b (str) – name of item b
Raises: ValueError
-
add_strict_preference
(a, b)¶ Adds a preference based on a > b
Parameters: - a (str) – name of item a that is preferred over item b
- b (str) – name of item b
Raises: ValueError
-
compute_entropy
(x)¶ Compute entropy of a new preference
Parameters: x (list) – pair of items Returns: Entropy for the pair of items
-
indifferent_log_probability
(preference, weights)¶ Computes the log probability for an indifferent preference
Parameters: - preference (tuple) – indifference preference relationship (a == b)
- weights (Numpy Array) – weights for each feature
Returns: Log probability of indifferent preference given weights
-
infer_weights
(method='MAP', iterations=100)¶ Infer weights for each attribute based on preferences. method=’MAP’ uses gradient based optimisation to compute the maximum a posteriori, method=’mean’ uses sampling to compute a better estimate of the weights when using non-normal priors
Parameters: - method (str) – method used for inference
- iterations (int) – number of iterations to use when method=’mean’
Returns: Estimated weights using Bayesian inference
Raises: AttributeError
ValueError
-
log_probability
(weights)¶ Computes the log posterior probability based on the sum of each strict and indifferent preference probability
Parameters: weights (Numpy Array) – weights for each feature Returns: Log posterior probability given preference data and weights
-
rank
()¶ Rank items based on the inferred weights
Returns: Pandas DataFrame of ordered items and utility values
-
remove_last_strict_preference
()¶ Removed the most recently added strict preference
-
set_priors
(priors)¶ Set priors
Parameters: priors (list) – List of priors Raises: AttributeError
-
strict_log_probability
(preference, weights)¶ Computes the log probability for a strict preference
Parameters: - preference (tuple) – strict preference relationship (a > b)
- weights (Numpy Array) – weights for each feature
Returns: Log probability of strict preference given weights
-
suggest
(method='random')¶ Suggest a new item to compare with the most preferred item method=’random’ chooses a new pair that includes the top ranked item at random, method=’max_variance’ chooses a pair that includes the top ranked item and the item with greatest uncertainty, method=’min_entropy’ chooses a pair that includes the top ranked item and minimises expected entropy
Parameters: method (str) – suggestion method one of ‘random’, ‘max_variance’ or ‘min_entropy’ Returns: Pair of items that includes the top ranked item and another item based on the selected method Raises: ValueError
-
suggest_new_pair
(method='random')¶ Suggest a new pair of items with minimum entropy method=’random’ chooses a new pair at random, method=’min_entropy’ chooses a new pair that minimises expected entropy
Parameters: method (str) – suggestion method one of ‘random’ or ‘min_entropy’ Returns: Pair of items that based on the selected method Raises: ValueError