[mlpack] PCA eigenvector save / load?

Marcus Edel marcus.edel at fu-berlin.de
Tue Sep 5 19:32:57 EDT 2017


Hello Jamie,

One solution would be to use:
http://www.mlpack.org/docs/mlpack-2.2.5/doxygen/classmlpack_1_1pca_1_1PCAType.html#a657771c335d4a28141e2abfbcba8c2e8
and do something like:

// Fake data.
arma::mat data("1 0 2 3 9;"
               "5 2 8 4 8;"
               "6 7 3 1 8");

arma::mat transformedData, eigvec
arma::vec eigVal;

// Get eigvec and save for later.
PCA pca;
pca.Apply(data, transformedData, eigVal, eigvec);
data::Save("eigvec.csv", eigvec);

// Load eigvec to project samples.
data::Load("eigvec.csv", eigvec);

// Center new data into a temporary matrix.
arma::mat centeredData;
math::Center(data, centeredData);

// Project the samples to the principals.
transformedData = arma::trans(eigvec) * centeredData;

Let me know if that could work for you.

Thanks,
Marcus

> On 5. Sep 2017, at 23:28, Jamie Bullock <jamie at jamiebullock.com> wrote:
> 
> 
> Dear list,
> 
> I'm new to mlpack and considering using it in a project for the PCA class.
> 
> Is it possible to save eigenvectors / values from the PCA and load them at a later point so that new vectors can be projected into the existing PC space?
> 
> Thanks
> 
> Jamie
> 
> Sent on the move
> _______________________________________________
> mlpack mailing list
> mlpack at lists.mlpack.org
> http://knife.lugatgt.org/cgi-bin/mailman/listinfo/mlpack



More information about the mlpack mailing list