base#
Classes#
BaseModel for Machine Learning Models |
|
Provide a description of a model instance to allow serialization. |
Module Contents#
- class base.BaseModel(features: list[str], targets: list[str] | None = None, name: str | None = None, distribution_strategy=None, output_dir: pathlib.Path = Path(gettempdir()))#
Bases:
abc.ABC
BaseModel for Machine Learning Models
- Parameters:
name – A name for this model - by default this will be the class name
features – List of the input feature names
targets – List of the target feature names
distribution_strategy – A tensorflow distribution strategy when trying to distribute the training across multiple devices
output_dir – model / experiment specific output directory
- input_specs: ClassVar[OrderedDict[str, damast.core.DataSpecification]]#
- features: list[str]#
- output_specs: ClassVar[OrderedDict[str, damast.core.DataSpecification]]#
- targets: list[str]#
- name: str#
- model: keras.Model#
- distribution_strategy: object | None#
- model_dir: pathlib.Path#
- history: keras.callbacks.History#
- abstract _init_model()#
Initialize the internal keras model, i.e. self.model.
- load_weights(checkpoint_filepath: str | pathlib.Path)#
Load the model weight from an existing checkpoint named by the checkpoint_filepath
- Parameters:
checkpoint_filepath – Name of the checkpoint filepath (prefix)
- build(optimizer: str | keras.optimizers.Optimizer = keras.optimizers.Adam(0.001), loss_function: str | keras.losses.Loss = 'mse', metrics: list[str] | list[keras.metrics.Metric] = ['mse'], **kwargs)#
Build / Compile the actual model
- Parameters:
optimizer – Name of the optimizer or an instance of keras.optimizers.Optimizer
loss_function – Name of the loss function or an instance of keras.losses.Loss
metrics – List of names of the metrics that shall be used, or list of instance of keras.metrics.Metrics
kwargs – additional arguments that can be forwarded to keras.engine.training.Model.compile
- plot(suffix='.png') pathlib.Path #
Plot the current model instance.
- Parameters:
suffix – Suffix that shall be used for the plot file
- Returns:
Path to the plotted file
- property checkpoints_dir: pathlib.Path#
Directory for the checkpoints.
- Returns:
Path to the checkpoints directory
- property evaluation_file: pathlib.Path#
Path to the evaluation file storing the results
- Returns:
evaluation file
- train(training_data: tf.data.Dataset, validation_data: tf.data.Dataset, monitor: str = 'val_loss', mode: str = 'min', epochs: int = 1, initial_epoch: int = 0, save_history: bool = True, **kwargs) None #
- get_evaluations() damast.core.types.DataFrame #
Read the evaluation results from the evaluation file.
- Raises:
FileNotFoundError – If evaluation result file does not exist
- save() pathlib.Path #
Save the model in the model directory.
- Returns:
Path to the saved model.
- evaluate(label: str, evaluation_data: tf.data.Dataset, **kwargs) dict[str, any] #
Evaluate this model.
- Parameters:
label – Custom label for this evaluation, e.g., can be the name of the dataset being used
evaluation_data – The data that shall be used for evaluation
- Returns:
DataFrame listing all performed evaluation results for this model