Some baseline models
Models to be used as baselines for choice modeling. Nothing smart here.
DistribMimickingModel
Bases: ChoiceModel
Dumb class model that mimicks the probabilities.
It stores the encountered in the train datasets and always returns them
Source code in choice_learn/models/baseline_models.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
trainable_weights
property
Trainable weights of the model.
__init__(**kwargs)
compute_batch_utility(shared_features_by_choice, items_features_by_choice, available_items_by_choice, choices)
Return utility that is fixed. U = log(P).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shared_features_by_choice |
tuple of np.ndarray (choices_features)
|
a batch of shared features Shape must be (n_choices, n_shared_features) |
required |
items_features_by_choice |
tuple of np.ndarray (choices_items_features)
|
a batch of items features Shape must be (n_choices, n_items_features) |
required |
available_items_by_choice |
ndarray
|
A batch of items availabilities Shape must be (n_choices, n_items) |
required |
choices_batch |
ndarray
|
Choices Shape must be (n_choices, ) |
required |
Returns:
Type | Description |
---|---|
ndarray(n_choices, n_items)
|
Utilities |
Raises:
Type | Description |
---|---|
ValueError
|
If the model has not been fitted cannot evaluate the utility |
Source code in choice_learn/models/baseline_models.py
fit(choice_dataset, *args, **kwargs)
Compute the choice frequency of each product and defines it as choice probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
choice_dataset |
ChoiceDataset
|
Dataset to be used for fitting |
required |
Source code in choice_learn/models/baseline_models.py
RandomChoiceModel
Bases: ChoiceModel
Dumb model that randomly attributes utilities to products.
Source code in choice_learn/models/baseline_models.py
trainable_weights
property
Return an empty list - there is no trainable weight.
__init__(**kwargs)
compute_batch_utility(shared_features_by_choice, items_features_by_choice, available_items_by_choice, choices)
Compute the random utility for each product of each choice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
shared_features_by_choice |
tuple of np.ndarray (choices_features)
|
a batch of shared features Shape must be (n_choices, n_shared_features) |
required |
items_features_by_choice |
tuple of np.ndarray (choices_items_features)
|
a batch of items features Shape must be (n_choices, n_items_features) |
required |
available_items_by_choice |
ndarray
|
A batch of items availabilities Shape must be (n_choices, n_items) |
required |
choices_batch |
ndarray
|
Choices Shape must be (n_choices, ) |
required |
Returns:
Type | Description |
---|---|
Tensor
|
(n_choices, n_items) matrix of random utilities |