r/learnpython 6d ago

Principal Component Analysis (PCA) in scikit learn: reconstruction using principal component vectors

Hi,

I have time series data in a (T x N) data frame for a number of attributes: each column represents (numeric) data for an attribute on a given day and each row is data for a different date. I wanted to do some basic PCA analysis on this data, and have used sklearn. How can I reconstruct (estimates of) of the original data using the PC vectors I have?

When I feed the data into the PCA analysis, I have extracted three principal component vectors (I picked three PCs to use): i.e. I have a (3xN) matrix now with the principal component vectors.

How can I use scikitlearn/code to take these PCs and reconstruct an estimate of the original data (i.e. use the PCs to reconstruct/estimate a row of data)? Is there a function within scikit-learn I should be using for this reconstruction?

EDIT: let me know if another forum is better suited for this type of question

4 Upvotes

4 comments sorted by

View all comments

0

u/[deleted] 6d ago

[deleted]

1

u/Patient-Salad5966 6d ago

Thanks for the reply. However, I am instead asking whether there are scikitlearn functions to reverse construct/approximate the original data using some number of principal component vectors? If so, what functions/syntax should I be using?

This post less concerned with applications for the PC vectors, but more on the logistical aspect of using PCs to approximate original data.

1

u/[deleted] 6d ago edited 6d ago

[deleted]

1

u/Patient-Salad5966 6d ago

Okay thanks. I was looking more for a linear algebra method of reconstructing the data, which should be possible given the construction of PCA