Latent Class SimpleMNL and ConditionalMNL
Latent Class MNL models.
LatentClassConditionalLogit
Bases: BaseLatentClassModel
Latent Class for ConditionalLogit.
Source code in choice_learn/models/latent_class_mnl.py
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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
__init__(n_latent_classes, fit_method, coefficients=None, epochs=100, add_exit_choice=False, tolerance=1e-06, optimizer='Adam', lr=0.001, **kwargs)
Initialize model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_latent_classes |
int
|
Number of latent classes. |
required |
fit_method |
str
|
Method to be used to estimate the model. |
required |
coefficients |
dict or MNLCoefficients
|
Dictionnary containing the parametrization of the model. The dictionnary must have the following structure: {feature_name_1: mode_1, feature_name_2: mode_2, ...} mode must be among "constant", "item", "item-full" for now (same specifications as torch-choice). |
None
|
epochs |
int
|
Number of epochs |
100
|
add_exit_choice |
bool
|
Whether to normalize probabilities with exit choice, by default False |
False
|
tolerance |
float
|
LBFG-S tolerance, by default 1e-6 |
1e-06
|
optimizer |
str
|
tf.keras.optimizers to be used, by default "Adam" |
'Adam'
|
lr |
float
|
Learning rate to use for optimizer if relevant, by default 0.001 |
0.001
|
Source code in choice_learn/models/latent_class_mnl.py
add_coefficients(coefficient_name, feature_name, items_indexes=None, items_names=None)
Add a coefficient to the model throught the specification of the utility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coefficient_name |
str
|
Name given to the coefficient. |
required |
feature_name |
str
|
features name to which the coefficient is associated. It should work with the names given. in the ChoiceDataset that will be used for parameters estimation. |
required |
items_indexes |
list of int
|
list of items indexes (in the ChoiceDataset) for which we need to add a coefficient, by default None |
None
|
items_names |
list of str
|
list of items names (in the ChoiceDataset) for which we need to add a coefficient, by default None |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
When names or indexes are both not specified. |
Source code in choice_learn/models/latent_class_mnl.py
add_shared_coefficient(coefficient_name, feature_name, items_indexes=None, items_names=None)
Add a single, shared coefficient to the model throught the specification of the utility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coefficient_name |
str
|
Name given to the coefficient. |
required |
feature_name |
str
|
features name to which the coefficient is associated. It should work with the names given. in the ChoiceDataset that will be used for parameters estimation. |
required |
items_indexes |
list of int
|
list of items indexes (in the ChoiceDataset) for which the coefficient will be used, by default None |
None
|
items_names |
list of str
|
list of items names (in the ChoiceDataset) for which the coefficient will be used, by default None |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
When names or indexes are both not specified. |
Source code in choice_learn/models/latent_class_mnl.py
fit(choice_dataset, **kwargs)
Fit the model to the choice_dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
choice_dataset |
ChoiceDataset
|
Dataset to fit the model to. |
required |
Source code in choice_learn/models/latent_class_mnl.py
instantiate(choice_dataset)
Instantiate of the Latent Class MNL model.
Source code in choice_learn/models/latent_class_mnl.py
instantiate_latent_models(choice_dataset)
Instantiate of the Latent Models that are SimpleMNLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
choice_dataset |
Used to match the features names with the model coefficients. |
required |
Source code in choice_learn/models/latent_class_mnl.py
LatentClassSimpleMNL
Bases: BaseLatentClassModel
Latent Class for SimpleMNL.
Source code in choice_learn/models/latent_class_mnl.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 |
|
__init__(n_latent_classes, fit_method, epochs=100, batch_size=128, add_exit_choice=False, tolerance=1e-06, intercept=None, optimizer='Adam', lr=0.001, **kwargs)
Initialize model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_latent_classes |
int
|
Number of latent classes. |
required |
fit_method |
str
|
Method to be used to estimate the model. |
required |
epochs |
int
|
Number of epochs |
100
|
add_exit_choice |
bool
|
Whether to normalize probabilities with exit choice, by default False |
False
|
tolerance |
float
|
LBFG-S tolerance, by default 1e-6 |
1e-06
|
intercept |
str
|
Type of intercept to include in the SimpleMNL. Must be in (None, 'item', 'item-full', 'constant'), by default None |
None
|
optimizer |
str
|
tf.keras.optimizers to be used, by default "Adam" |
'Adam'
|
lr |
float
|
Learning rate to use for optimizer if relevant, by default 0.001 |
0.001
|
Source code in choice_learn/models/latent_class_mnl.py
fit(choice_dataset, **kwargs)
Fit the model to the choice_dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
choice_dataset |
ChoiceDataset
|
Dataset to fit the model to. |
required |
Source code in choice_learn/models/latent_class_mnl.py
instantiate(n_items, n_shared_features, n_items_features)
Instantiate the Latent Class MNL model.
Source code in choice_learn/models/latent_class_mnl.py
instantiate_latent_models(n_items, n_shared_features, n_items_features)
Instantiate the Latent Models that are SimpleMNLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_items |
int
|
Number of items/aternatives to consider. |
required |
n_shared_features |
int
|
Number of shared features |
required |
n_items_features |
int
|
Number of items features |
required |