Book Image

Test Driven Machine Learning

Book Image

Test Driven Machine Learning

Overview of this book

Table of Contents (16 chapters)
Test-Driven Machine Learning
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Perceptively Testing a Perceptron
Index

Beginning the development


We start with the standard simplistic tests that will serve to get the basic wiring up for our classifier. First, the test:

import NaiveBayes

def no_observations_test():
  classifier = NaiveBayes.Classifier()
  classification = classifier.classify(observation=23.2)
  assert classification is None, "Should not classify observations without training examples."

And then the code:

class Classifier:
  def classify(self, observation):
    pass

As the next step to approach a solution, let's try the case where we've only observed the data from a single class:

def given_an_observation_for_a_single_class_test():
  classifier = NaiveBayes.Classifier()
  classifier.train(classification='a class', observation=0)
  classification = classifier.classify(observation=23.2)
  assert classification == 'a class', "Should always classify as given class if there is only one."

A very simple solution is to just set a single classification that gets set every time we train something:

class Classifier...