Testing

Learn testing with map-reduce using classifier strategies in the Hyperparameter class.

We'll cover the following

Overview

The testing process can also be defined as a higher-order function, a function that accepts a function as a parameter value. We can summarize the testing effort as a map-reduce problem. Given a Hyperparameter with a kk value and a distance algorithm, we need to use an iterator for the following two steps:

  • A function classifies all test samples, mapping each test sample to 11 if the classification was correct or 00 for an incorrect classification. This is the map part of map-reduce.

  • A function computes a summary with the count of correct values from the long sequence of actual classified samples. This is the reduce part of map-reduce.

Python provides high-level functions for these map and reduce operations. This allows us to focus on the details of the mapping and ignore the boilerplate part of iterating over the data items.

Looking forward to the next section, we’ll want to refactor the Hyperparameter class to split the classifier algorithm into a separate, standalone function. We’ll make the classifier function a Strategy that we provide when we create an instance of the Hyperparameter class. Doing this means we can more easily experiment with some alternatives. We’ll look at three different ways to approach refactoring a class.

Implementation

Here’s one definition that relies on an external classifier function:

Get hands-on with 1200+ tech skills courses.