runn.models.altspec_nn
warning_manager = WarningManager()
module-attribute
#
AltSpecNN(attributes=None, n_alt=None, alt_spec_attrs=None, shared_attrs=None, socioec_attrs=None, layers_dim=[25, 25], activation='relu', regularizer=None, regularization_rate=0.001, dropout=0.0, batch_norm=False, learning_rate=0.001, optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'], filename=None, warnings=True)
#
Bases: DNN
Alternative-specific neural network model for choice modeling.
PARAMETER | DESCRIPTION |
---|---|
attributes |
List with the attributes names in the model, in the same order as in the input data. If None, the model cannot be initialized unless it is loaded from a file. Default: None. |
n_alt |
Number of alternatives in the choice set. If None, the model cannot be initialized unless it is loaded from a file. Default: None. |
alt_spec_attrs |
Dictionary with the alternative-specific attributes. The keys are the index of the alternative and the values are lists with the names of the alternative-specific attributes. The alternative-specific attributes must be a subset of the attributes defined in the model. If None, the model cannot be initialized unless it is loaded from a file. Default: None. |
shared_attrs |
List with the names of the attributes that are shared across all alternatives. The shared attributes must be a subset of the attributes defined in the model. If None, the model cannot be initialized unless it is loaded from a file. Default: None. |
socioec_attrs |
List with the names of the socio-economic attributes of each decision maker. The socio-economic attributes must be a subset of the attributes defined in the model. If None, the model cannot be initialized unless it is loaded from a file. Default: None. |
layers_dim |
List with the number of neurons in each hidden layer, the length of the list is the number of hidden layers. Default: [25, 25].
TYPE:
|
activation |
Activation function to use in the hidden layers. Can be either a string or a list of strings. See https://keras.io/api/layers/activations/ for the available activations. Default: 'relu'. |
regularizer |
Type of regularization to apply. Possible values: 'l1', 'l2' or 'l1_l2'. Default: None. |
regularization_rate |
Regularization rate if regularizer is not None. Default: 0.001.
TYPE:
|
learning_rate |
Learning rate of the optimizer. Default: 0.001.
TYPE:
|
dropout |
Dropout rate to use in the hidden layers. Can be either a float or a list of floats. If a float is provided, the same dropout rate will be used in all the hidden layers. Default: 0.0. |
batch_norm |
Whether to use batch normalization or not. Default: False.
TYPE:
|
optimizer |
Optimizer to use. Can be either a string or a tf.keras.optimizers.Optimizer. Default: 'adam'. |
loss |
Loss function to use. Can be either a string or a tf.keras.losses.Loss. Default: 'categorical_crossentropy'. |
metrics |
List of metrics to be evaluated by the model during training and testing. Each of this can be either a string or a tf.keras.metrics.Metric. Default: ['accuracy'].
TYPE:
|
filename |
Load a previously trained model from a file. If None, a new model will be initialized. When loading a model from a file, the previous parameters will be ignored. Default: None. |
warnings |
Whether to show warnings or not. Default: True.
TYPE:
|
Source code in runn/models/altspec_nn.py
get_utility(x, name='AltSpecNN_Utility')
#
Get the utility of each alternative for a given set of observations.
PARAMETER | DESCRIPTION |
---|---|
x |
The input data. It can be a tf.Tensor, np.ndarray or pd.DataFrame.
TYPE:
|
name |
Name of the utility model. Default: 'AltSpecNN_Utility'.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ndarray
|
Numpy array with the utility of each alternative for each observation in the input data. |
Source code in runn/models/altspec_nn.py
load(path)
#
Load the model from a file.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the file where the model is saved.
TYPE:
|
Source code in runn/models/altspec_nn.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
save(path='model.zip')
#
Save the model to a file. The model must be fitted before saving it.
PARAMETER | DESCRIPTION |
---|---|
path |
Path to the file where the model will be saved. Default: 'model.zip'.
TYPE:
|