Overview
TheVisualizationGenerator class creates publication-quality matplotlib visualizations from experiment state. It produces three types of plots to analyze experiment performance over time.
Features
- Headless rendering - Works in server environments without display
- Graceful error handling - Each plot wrapped in try/except to prevent crashes
- Clean styling - Professional defaults with customizable DPI and sizing
- Automatic best result highlighting - Visual emphasis on top-performing experiments
Class Definition
VisualizationGenerator
No parameters required. Matplotlib settings are configured automatically with professional defaults.
Methods
generate()
Generate all visualizations from experiment state.Complete experiment state after all iterations, containing:
experiments: List of all ExperimentResult objectsbest_experiment: Name of best-performing experimentconfig.primary_metric: Metric to visualize
Base output directory. Plots are saved to
output_dir/plots/list[Path] - List of paths to generated PNG files
Generated plots:
metric_progression.png- Line chart of metric over iterationsmodel_comparison.png- Bar chart comparing model typesimprovement_over_baseline.png- Baseline vs best model comparison
Generated Visualizations
1. Metric Progression
Line plot showing primary metric value across all iterations. Features:- Blue line connecting all successful experiments
- Gold star marking the best result
- X-axis: Iteration number
- Y-axis: Primary metric value
Only successful experiments with the primary metric are included.
2. Model Comparison
Bar chart comparing best performance of each model type. Features:- Groups results by model type
- Shows best metric achieved per model
- Best overall model highlighted in green
- Value labels on top of each bar
- Rotated x-axis labels for readability
- LogisticRegression
- RandomForestClassifier
- XGBClassifier
- etc.
3. Improvement Over Baseline
Side-by-side comparison of baseline vs best model. Features:- Two bars: baseline (orange) and best (green)
- Percentage improvement in title
- Value labels on bars
- Automatic handling of “higher is better” vs “lower is better” metrics
Matplotlib Configuration
Default settings applied:Metric Direction Detection
Automatically determines if lower or higher values are better:- RMSE, MSE, MAE
- Log Loss
- Error rates
- Accuracy, Precision, Recall, F1
- R² Score, ROC AUC
Error Handling
Each plot generation is wrapped individually:Complete Example
Integration with MLflow
Visualization paths can be logged to MLflow:Plot Generation Conditions
Plots are only generated when sufficient data exists:Metric Progression
- Requires: At least 1 successful experiment with primary metric
- Skips if: No successful experiments or primary_metric not set
Model Comparison
- Requires: At least 1 successful experiment with primary metric
- Skips if: No successful experiments or primary_metric not set
- Groups by:
model_typefield from results
Improvement Over Baseline
- Requires:
- First experiment (baseline) succeeded
- Baseline has primary metric
- Best metric exists and is non-zero
- Skips if: Any requirement not met
Customizing Output Directory
The
plots/ subdirectory is always created automatically.Accessing Individual Plots
Headless Rendering
The generator uses theAgg backend for headless environments:
This allows visualization generation on servers without graphical displays (Docker, SSH sessions, etc.).
Colors and Styling
Standard colors:- Primary line/bars:
#2196F3(blue) - Best result marker:
#4CAF50(green) - Baseline:
#FF9800(orange) - Best model:
#4CAF50(green)
- Font: System default
- Value labels: 9-11pt, bold for emphasis
- Grid: Alpha 0.3 for subtle guidance
Source Location
~/workspace/source/src/execution/visualization_generator.py