callback that records events into a history object this callback is automatically applied to every keras model the history object gets returned by the fit method of models example model sequentiallayers dense10 model compilesgd loss mse history model fitnp arange100 reshape5 20 np zeros5 epochs10 verbose1 printhistory params verbose 1 epochs 10 steps 1 check the keys of history object printhistory history keys dictkeys loss set the history attribute on the model after the epoch ends this will make sure that the state which is set is the latest one callback that records events into a history object this callback is automatically applied to every keras model the history object gets returned by the fit method of models example model sequential layers dense 10 model compile sgd loss mse history model fit np arange 100 reshape 5 20 np zeros 5 epochs 10 verbose 1 print history params verbose 1 epochs 10 steps 1 check the keys of history object print history history keys dict_keys loss set the history attribute on the model after the epoch ends this will make sure that the state which is set is the latest one
from keras.api_export import keras_export
from keras.callbacks.callback import Callback


@keras_export("keras.callbacks.History")
class History(Callback):
    

    def __init__(self):
        super().__init__()
        self.history = {}

    def on_train_begin(self, logs=None):
        self.epoch = []

    def on_epoch_end(self, epoch, logs=None):
        logs = logs or {}
        self.epoch.append(epoch)
        for k, v in logs.items():
            self.history.setdefault(k, []).append(v)

        
        
        self.model.history = self