In production ML systems, canary deployments are a critical strategy for safely rolling out new model versions. A small percentage of traffic is routed to the new (canary) model while the majority continues to use the existing (baseline) model. By comparing their performance, you can decide whether to promote the canary to full production or roll back.
Given prediction results from both canary and baseline models, compute key comparison metrics to determine if the canary deployment is healthy.
Each result in both lists is a dictionary with:
Write a function analyze_canary_deployment(canary_results, baseline_results, accuracy_tolerance, latency_tolerance) that computes:
Each relative change is (canary - baseline) / baseline * 100. Both tolerances are relative fractions (0.05 means 5%): promote only when accuracy_change_pct >= -accuracy_tolerance * 100 and latency_change_pct <= latency_tolerance * 100.
If either input list is empty, return an empty dictionary.
All numeric values should be rounded to 2 decimal places except accuracy values which should be rounded to 4 decimal places.