ehrapy.ml.Trainer#

class ehrapy.ml.Trainer(*, max_epochs=100, batch_size=128, learning_rate=0.001, weight_decay=0.0001, patience=10, class_weight=None, device='auto')[source]#

How deep learning models are trained.

Training stops once the loss on the tuning set has not improved for patience epochs, and the parameters of the epoch with the lowest loss are kept.

Examples

>>> import ehrapy as ep
>>> model = ep.ml.GRU(trainer=ep.ml.Trainer(max_epochs=20, device="cpu"))

Attributes table#

batch_size

Number of observations per gradient step.

class_weight

"balanced" to weigh classes and labels inversely to their frequency in the training set.

device

Device to train and predict on, such as "cpu" or "cuda", or "auto" for a GPU if one is available.

learning_rate

Learning rate of the AdamW optimizer.

max_epochs

Maximum number of passes over the training set.

patience

Number of epochs without improvement on the tuning set after which training stops.

weight_decay

Weight decay of the AdamW optimizer.

Methods table#

Attributes#

Trainer.batch_size: int = 128#

Number of observations per gradient step.

Trainer.class_weight: Literal['balanced'] | None = None#

“balanced” to weigh classes and labels inversely to their frequency in the training set.

Trainer.device: str = 'auto'#

Device to train and predict on, such as “cpu” or “cuda”, or “auto” for a GPU if one is available.

Trainer.learning_rate: float = 0.001#

Learning rate of the AdamW optimizer.

Trainer.max_epochs: int = 100#

Maximum number of passes over the training set.

Trainer.patience: int = 10#

Number of epochs without improvement on the tuning set after which training stops.

Trainer.weight_decay: float = 0.0001#

Weight decay of the AdamW optimizer.

Methods#