Hexbin Plot

Machine Learning Loss

Training hexbin showing learning rate vs final loss relationship

Output
Machine Learning Loss
Python
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.colors import LinearSegmentedColormap

np.random.seed(5555)
lr = np.random.lognormal(-5, 1, 6000)
loss = 1 / (1 + 1000*lr) + np.abs(lr - 0.01) * 10 + np.random.exponential(0.1, 6000)

fig, ax = plt.subplots(figsize=(10, 8), facecolor='#0f0a1a')
ax.set_facecolor('#0f0a1a')

colors = ['#0f0a1a', '#2a1a4a', '#4a2a7a', '#6a3aaa', '#8a4ada', '#aa6aff', '#cc9aff', '#eeccff']
cmap = LinearSegmentedColormap.from_list('ml', colors, N=256)

hb = ax.hexbin(np.log10(lr), np.log10(loss), gridsize=30, cmap=cmap, mincnt=1, edgecolors='none')

cbar = plt.colorbar(hb, ax=ax, pad=0.02, shrink=0.8)
cbar.ax.set_facecolor('#0f0a1a')
cbar.outline.set_edgecolor('#4a2a7a')
cbar.ax.tick_params(colors='#aa6aff', labelsize=9)
cbar.set_label('Experiments', color='#aa6aff', fontsize=10)

ax.set_xlabel('Learning Rate (log10)', color='#aa6aff', fontsize=11)
ax.set_ylabel('Final Loss (log10)', color='#aa6aff', fontsize=11)
ax.tick_params(colors='#aa6aff', labelsize=10)
for spine in ax.spines.values():
    spine.set_visible(False)

plt.tight_layout()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support