O'Reilly logo

Test-Driven Machine Learning by Justin Bozonier

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A bootstrapping bandit

Now, let's move to implement a simple approach that will use what we've been exploring. A bootstrapping bandit requires no math knowledge at all. It just requires us to sample from the data that we've encountered. Due to this simplicity, we can start from here. Let's start with the simplest test, as follows:

import rpm_bandit

def given_a_single_treatment_test():
  bandit = rpmbandit.RPMBandit(['A'])
  chosen_treatment = bandit.choose_treatment()
  assert chosen_treatment == 'A', 'Should choose the only available option.'

Okay, it's pretty standard at this point. The code that I've written to make this pass is also pretty standard now:

class RPMBandit: def __init__(self, treatments): self._treatments = treatments def choose_treatment(self): ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required