PCA

The PCA algorithms in the Shark-ML library are implemented in the PCA class. Objects of this class should be configured with the number of target dimensions. We can use the encoder() method for this. This method takes two parameters: the first one is the reference to the object of the LinearModel class, while the second one is the number of target dimensions. After the object of the LinearModel class has been configured, it can be used for data transformation regarding the functional object. Its called result is a new object of the Data<RealVector> class:

 void PCAReduction(const UnlabeledData<RealVector> &data, 
const UnlabeledData<RealVector>& lables,
size_t target_dim) {
PCA pca(data);
LinearModel<> encoder;
pca.encoder(encoder, target_dim);
auto new_data = encoder(data);

for (size_t i = 0; i < new_data.numberOfElements(); ++i) {
auto x = new_data.element(i)[0];
auto y = new_data.element(i)[1];
}
}

The following graph shows the result of applying the Shark-ML PCA implementation to our data:

..................Content has been hidden....................

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