Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Test Driven Machine Learning

You're reading from  Test Driven Machine Learning

Product type Book
Published in Nov 2015
Publisher
ISBN-13 9781784399085
Pages 190 pages
Edition 1st Edition
Languages

Table of Contents (16) Chapters

Test-Driven Machine Learning
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Introducing Test-Driven Machine Learning 2. Perceptively Testing a Perceptron 3. Exploring the Unknown with Multi-armed Bandits 4. Predicting Values with Regression 5. Making Decisions Black and White with Logistic Regression 6. You're So Naïve, Bayes 7. Optimizing by Choosing a New Algorithm 8. Exploring scikit-learn Test First 9. Bringing It All Together Index

Starting from scratch


To begin with, let's start building an extremely simplistic bandit algorithm. The actual bandit class will have two methods: choose_treatment and log_payout. The first method will recommend the best treatment to choose, and log_payout will be used to report back on how effective the recommended treatment was.

The simplest way to approach this algorithm from a test-driven perspective is to start with a single treatment so that the algorithm only has one thing to recommend. The code for this test looks like the following:

from nose.tools import assert_equal
import simple_bandit

def given_a_single_treatment_test():
  bandit = simple_bandit.SimpleBandit(['A'])
  chosen_treatment = bandit.choose_treatment()
  assert_equal(chosen_treatment, 'A', 'Should choose the only available option.')

Again, we'll start from such a simple place that making the test pass will seem too easy:

class SimpleBandit:
  def __init__(self, treatments):
    self._treatments = treatments
  def choose_treatment...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}