The TrainingData Class

Learn how the TrainingData class enables data loading, partitioning, and testing with hyperparameters for future algorithm implementations.

The TrainingData class has listed two subclasses of Sample objects. The KnownSample and UnknownSample can be implemented as extensions to a common parent class, Sample.

Methods

The TrainingData class also has a list with Hyperparameter instances. This class can have simple, direct references to previously defined classes. This class has two methods that initiate the processing:

  • The load() method reads raw data and partitions it into training data and test data. Both of these are essentially KnownSample instances with different purposes. The training subset is for evaluating the k-NN algorithm; the testing subset is for determining how well the k hyperparameter is working.

  • The test() method uses a Hyperparameter object, performs the test, and saves the result. Looking back at Chapter 1’s context diagram, we see three stories:

    • Provide training data
    • Set parameters and test classifier
    • Make classification request

It seems helpful to add a method to perform a classification using a given Hyperparameter instance. This would add a classify() method to the TrainingData class.

Here’s the start of the class definition:

Get hands-on with 1200+ tech skills courses.