Normalizing with Shark-ML

The Shark-ML library implements several normalization approaches. They are implemented as trainer classes for the Normalizer model type. We can reuse the Normalizer type after training on different data. There are the following normalization trainer classes:

  • NormalizeComponentsUnitInterval—This class trains a normalization model that transforms data to fit a unit interval.
  • NormalizeComponentsUnitVariance—This class trains a normalization model that transforms data to have unit variance and, optionally, a zero mean.
  • NormalizeComponentsWhitening—This class trains a normalization model that transforms data to have zero mean and unit variance by default, but we can specify the target variance value.

The following code sample shows how to use a normalization model with a trainer:

#include <shark/Algorithms/Trainers/NormalizeComponentsUnitVariance.h>
#include <shark/Models/Normalizer.h>
...
Normalizer<RealVector> normalizer;
NormalizeComponentsUnitVariance<RealVector> normalizingTrainer(
/*removeMean*/ true);
normalizingTrainer.train(normalizer, dataset.inputs());
dataset = transformInputs(dataset, normalizer);

After defining the model and the trainer objects, we have to call the train() method to learn statistics from the input dataset, and then we use the transformInputs() function to update the target dataset. We can print a Shark-ML dataset with the standard C++ streaming operator, as follows:

std::cout << dataset << std::endl;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.79.206