Data: Tabular Time Series Specialty: Endocrinology Laboratory: Blood Tests EHR: Demographics Diagnoses Medications Omics: Genomics Multi-omics Transcriptomics Wearable: Activity Clinical Purpose: Treatment Response Assessment Task: Biomarker Discovery
[c23b31]: / src / move / visualization / loss_curves.py

Download this file

45 lines (36 with data), 1.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
__all__ = ["LOSS_LABELS", "plot_loss_curves"]
from collections.abc import Sequence
import matplotlib.figure
import matplotlib.pyplot as plt
import numpy as np
from move.visualization.style import (
DEFAULT_PLOT_STYLE,
DEFAULT_QUALITATIVE_PALETTE,
color_cycle,
style_settings,
)
LOSS_LABELS = ("Loss", "Cross-Entropy", "Sum of Squared Errors", "KLD")
def plot_loss_curves(
losses: Sequence[list[float]],
labels: Sequence[str] = LOSS_LABELS,
style: str = DEFAULT_PLOT_STYLE,
colormap: str = DEFAULT_QUALITATIVE_PALETTE,
) -> matplotlib.figure.Figure:
"""Plot one or more loss curves.
Args:
losses: List containing lists of loss values
labels: List containing names of each loss line
style: Name of style to apply to the plot
colormap: Name of colormap to use for the curves
Returns:
Figure
"""
num_epochs = len(losses[0])
epochs = np.arange(num_epochs)
with style_settings(style), color_cycle(colormap):
fig, ax = plt.subplots()
for loss, label in zip(losses, labels):
ax.plot(epochs, loss, label=label, linestyle="-")
ax.legend()
ax.set(xlabel="Epochs", ylabel="Loss")
return fig