#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
Experimentation

A/B Testing for Machine Learning

While A/B testing is a general experimentation technique, it plays a specific and critical role in machine learning: validating that a new model actually performs better than the current one in the real world, not just on a static test set.

Why Offline Metrics Aren't Enough

A model can score well on offline metrics like accuracy or RMSE but still fail to improve real business outcomes once deployed, due to shifts in live data or downstream effects not captured in historical data. A/B testing closes that gap.

Typical ML A/B Test Setup

GroupWhat They See
ControlPredictions from the current production model
TreatmentPredictions from the new candidate model

Traffic is randomly split between the two, and a business metric (click-through rate, conversion, revenue) is compared between groups using a statistical significance test.

Best Practices for ML A/B Testing

  • Pick One Primary Metric: Avoid overloading the test with too many success criteria.
  • Run Long Enough: Capture enough traffic and time to reach statistical power.
  • Monitor Guardrail Metrics: Ensure the new model doesn't hurt other important metrics.
  • Shadow Testing First: Run the new model silently alongside production before a live A/B test.

Common Pitfalls

  • Comparing models trained on different time windows, introducing bias.
  • Stopping the test too early once results look favorable.
  • Ignoring interaction effects between the new model and other running experiments.
Key Takeaway: A model isn't proven better until it wins a live A/B test — offline metrics are a filter, not a final verdict.

Planning the Experiment Before Launch

A model A/B test should be designed on paper before any traffic moves. Writing the plan first stops people from changing the goal after they see the numbers.

  1. State the hypothesis: "The new ranking model raises click-through rate on the home feed."
  2. Pick the randomisation unit: usually the user, so one person does not bounce between models and get a mixed experience.
  3. Set the minimum detectable effect: the smallest lift that would be worth shipping.
  4. Estimate sample size from the baseline rate, that effect, the significance level and the desired power.
  5. Fix the duration to cover full weekly cycles, since behaviour on weekends often differs.
from statsmodels.stats.power import NormalIndPower
from statsmodels.stats.proportion import proportion_effectsize

baseline = 0.040      # current click-through rate
target   = 0.042      # smallest rate worth shipping
effect = proportion_effectsize(target, baseline)
n_per_group = NormalIndPower().solve_power(effect, alpha=0.05, power=0.8)
print(round(n_per_group))   # users needed in each group

Reading the Results Correctly

Suppose control shows 4,000 clicks from 100,000 users and treatment shows 4,300 clicks from 100,000 users. A two-proportion z-test tells you whether that gap is likely to be noise.

from statsmodels.stats.proportion import proportions_ztest

clicks = [4300, 4000]
users  = [100000, 100000]
stat, p_value = proportions_ztest(clicks, users)
print(f"z = {stat:.2f}, p = {p_value:.4f}")

A small p-value suggests a real difference, but also report the confidence interval of the lift. "Between a small and a moderate gain" helps decision makers more than a single number.

Before trusting any result, run a sample ratio mismatch check. If you planned a 50/50 split but the groups came out very uneven, something in assignment or logging is broken, and the outcome cannot be trusted.

Alternatives When a Classic Split Does Not Fit

MethodGood forTrade-off
InterleavingComparing two ranking or search models quicklyMeasures preference, not business metrics directly
Multi-armed banditShifting traffic towards the winner while testingHarder to get clean effect estimates
Switchback testMarketplaces where users affect each other, such as pricing or dispatchNeeds careful time-slot design
Canary releaseChecking stability and latency on a small sliceUsually too small to judge business impact

Launch Checklist

  • Both models log predictions, model version and user ID so results can be joined later.
  • Latency of the new model is measured, since a slower model can lower engagement on its own.
  • Novelty effects are watched: an early jump that fades after a week is common.
  • Segments such as new versus returning users are checked, but only those planned in advance.
  • A rollback switch exists and has been tested.

Ready to master Machine Learning?

Build real-world machine learning skills with hands-on projects, mentor-led sessions, and industry-relevant tools.

Explore Course