GnuplotEx.ML.Loss (gnuplot_ex v0.5.0)
Helpers for plotting training metrics and loss curves.
Provides convenient functions for common machine learning visualization patterns including loss curves, training vs validation comparisons, and multi-metric plots.
Examples
# Simple loss curve
train_loss = [0.9, 0.7, 0.5, 0.3, 0.2]
val_loss = [0.95, 0.75, 0.6, 0.45, 0.35]
plot = GnuplotEx.ML.Loss.plot(train_loss, val_loss)
GnuplotEx.render(plot, :svg)
# Multiple metrics
metrics = %{
train_loss: [0.9, 0.7, 0.5, 0.3, 0.2],
val_loss: [0.95, 0.75, 0.6, 0.45, 0.35],
train_acc: [0.6, 0.7, 0.8, 0.85, 0.9],
val_acc: [0.55, 0.68, 0.75, 0.82, 0.88]
}
plot = GnuplotEx.ML.Loss.plot_metrics(metrics,
title: "Training Progress",
x_label: "Epoch"
)
Summary
Functions
Plot training and validation loss curves.
Plot multiple metrics on the same plot.
Plot a single loss/metric curve.
Functions
Plot training and validation loss curves.
Creates a line plot showing both training and validation loss over epochs/iterations, making it easy to identify overfitting or underfitting patterns.
Options
:title- Plot title (default: "Training Progress"):x_label- Label for x-axis (default: "Epoch"):y_label- Label for y-axis (default: "Loss"):train_label- Label for training line (default: "Training Loss"):val_label- Label for validation line (default: "Validation Loss"):train_color- Color for training line (default: "#E95420" - Ubuntu orange):val_color- Color for validation line (default: "#0066CC" - blue):line_width- Line width (default: 2):legend- Legend position (default: :top_right)
Examples
iex> train_loss = [0.9, 0.7, 0.5, 0.3, 0.2]
iex> val_loss = [0.95, 0.75, 0.6, 0.45, 0.35]
iex> plot = GnuplotEx.ML.Loss.plot(train_loss, val_loss)
# Custom styling
iex> plot = GnuplotEx.ML.Loss.plot(train_loss, val_loss,
...> title: "Model Training",
...> x_label: "Iteration",
...> train_color: "#FF0000",
...> val_color: "#00FF00"
...> )
Plot multiple metrics on the same plot.
Takes a map of metric names to value lists and plots them all together. Useful for comparing multiple metrics (loss, accuracy, F1, etc.) in one view.
Options
:title- Plot title (default: "Training Metrics"):x_label- Label for x-axis (default: "Epoch"):y_label- Label for y-axis (default: "Value"):colors- Map of metric names to colors (auto-assigned if not provided):line_width- Line width (default: 2):legend- Legend position (default: :top_right)
Examples
iex> metrics = %{
...> train_loss: [0.9, 0.7, 0.5, 0.3, 0.2],
...> val_loss: [0.95, 0.75, 0.6, 0.45, 0.35],
...> train_acc: [0.6, 0.7, 0.8, 0.85, 0.9],
...> val_acc: [0.55, 0.68, 0.75, 0.82, 0.88]
...> }
iex> plot = GnuplotEx.ML.Loss.plot_metrics(metrics)
# With custom colors
iex> plot = GnuplotEx.ML.Loss.plot_metrics(metrics,
...> colors: %{
...> train_loss: "#E95420",
...> val_loss: "#0066CC",
...> train_acc: "#77DD77",
...> val_acc: "#FF6B6B"
...> }
...> )
Plot a single loss/metric curve.
Useful for plotting a single metric over time without train/val split.
Options
:title- Plot title (default: "Training Metric"):x_label- Label for x-axis (default: "Epoch"):y_label- Label for y-axis (default: "Value"):label- Line label (default: "Metric"):color- Line color (default: "#E95420"):line_width- Line width (default: 2)
Examples
iex> loss_values = [0.9, 0.7, 0.5, 0.3, 0.2]
iex> plot = GnuplotEx.ML.Loss.plot_single(loss_values,
...> title: "Training Loss",
...> y_label: "Cross-Entropy Loss"
...> )