runn.models.dnn
warning_manager = WarningManager()
module-attribute
#
DNN(attributes=None, n_alt=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: BaseModel
Deep 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. |
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/dnn.py
get_utility(x, name='DNN_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: 'DNN_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/dnn.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/dnn.py
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 |
|
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:
|