runn.models.altspec_mono_nn
warning_manager = WarningManager()
module-attribute
#
AltSpecMonoNN(attributes=None, n_alt=None, alt_spec_attrs=None, shared_attrs=None, socioec_attrs=None, monotonicity_constraints=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 monotonic 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. |
monotonicity_constraints |
Dictionary with the attributes that must be monotonic. The keys are the attribute names and the values are the monotonicity constraints. The constraints can be either an integer or a dictionary. If an integer is provided, the possible values are -1, 0 or 1, which represent decreasing, no monotonicity and increasing monotonicity, respectively. If a dictionary is provided, the keys are the index of the alternative and the values are the monotonicity constraints for the attribute in that alternative. If no monotonicity constraints are provided for an attribute, the default value is 0 (no monotonicity). If None, no monotonicity constraints will be applied. Default: None.
TYPE:
|
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_mono_nn.py
get_utility(x, name='AltSpecMonoNN_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: 'AltSpecMonoNN_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_mono_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_mono_nn.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
|
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:
|