ModelRefs / Data Visualization — Tutorial
Data Visualization — Tutorial
Plot training curves, distributions, and confusion matrices — the visuals every ML practitioner needs. Covers The essential plot types.
Overview
Plot training curves, distributions, and confusion matrices — the visuals every ML practitioner needs
Level: Beginner. Estimated reading time: 20 minutes.
The essential plot types
Matplotlib is the foundation of Python data visualization. Most ML work requires only four plot types:
Line plot: training loss and validation loss over epochs. The gap between them reveals overfitting.
Histogram: understand the distribution of a feature before modelling it. Skewed distributions often need log-transformation.
Scatter plot: relationship between two features, or predicted vs actual values. A perfect model gives points on the y=x diagonal.
Bar chart: comparison across categories — accuracy per class, feature importances, A/B test results.
The standard pattern: fig, ax = plt.subplots() creates a figure and axes object. ax.plot(), ax.hist(), etc. add data. ax.set_xlabel(), ax.set_title() add labels. plt.tight_layout() prevents overlap. plt.savefig("plot.png") saves it.
Visualizing model training
The two most important plots in any training run:
Loss curve: plot training loss and validation loss vs epoch. Both should decrease. If validation loss starts increasing while training loss decreases, you're overfitting — add regularisation or collect more data.
Confusion matrix: for classification, a grid showing how often the model confused each pair of classes. The diagonal is correct predictions. Off-diagonal entries are errors. Use seaborn.heatmap() or sklearn's ConfusionMatrixDisplay.
For regression: plot predicted vs actual values. Perfect predictions form a diagonal line. Systematic bias (all predictions too high) shows as a shifted line. Heteroscedasticity (errors grow with value) is visible as a fan pattern.
Continue your research
Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to Data Visualization — Tutorial.