# PCA transform

**URL:** <https://root-forum.cern.ch/t/pca-transform/17464>\
**Category:** TMVA\
**Created:** [April 4, 2014, 1:34pm UTC](https://root-forum.cern.ch/t/pca-transform/17464 "2014-04-04T13:34:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sidebo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/8e8cbc/32.png) [@sidebo](https://root-forum.cern.ch/u/sidebo)\
**Post date:** [April 4, 2014, 1:34pm UTC](https://root-forum.cern.ch/t/pca-transform/17464/1 "2014-04-04T13:34:53Z")

</div>

I’m new to ROOT and extremely new to TMVA. I want to make a PCA transform on my data. The data consists of 6 TTrees, each with around 7 entries in a 48-variable space (so 48 leaves per tree). Is there a way to do this with TMVA? I don’t want to do any classifier training, just find the principal components to be able to plot the data in the transformed space. Since I’m unexperienced I’d be grateful for some example piece of code.

---

<div class="post-metadata">

**Author:** ![brun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@brun](https://root-forum.cern.ch/u/brun)\
**Post date:** [April 4, 2014, 3:09pm UTC](https://root-forum.cern.ch/t/pca-transform/17464/2 "2014-04-04T15:09:02Z")

</div>

see class TPrincipal and example in $ROOTSYS/tutorials/math/principal.C

Rene

---

<div class="post-metadata">

**Author:** ![sidebo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/8e8cbc/32.png) [@sidebo](https://root-forum.cern.ch/u/sidebo)\
**Post date:** [April 7, 2014, 4:20pm UTC](https://root-forum.cern.ch/t/pca-transform/17464/3 "2014-04-07T16:20:32Z")

</div>

Ah, so I don’t need TMVA. But, from what I can see, there is no way to keep track of from where the data points came once they’ve been added, is there? The reason I want to use a PCA is that I would like to see if different samples (i.e. some number of data points) may be separated by looking at them along the principal components instead of the original components. Therefore, I want to keep track of each data point added by TPrincipal::AddRow(data). (Let’s say, for example, that one row of data was coloured yellow, and another red, so that even after the transformation, I can still see which data came from where.)

---

<div class="post-metadata">

**Author:** ![brun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@brun](https://root-forum.cern.ch/u/brun)\
**Post date:** [April 8, 2014, 6:54am UTC](https://root-forum.cern.ch/t/pca-transform/17464/4 "2014-04-08T06:54:20Z")

</div>

see TPrincipal::X2P(const Double\_t \*x, Double\_t \*p).  
This function converts your original point to PCA coordinates.  
It is up to you to run the loop on your data points and make any correlation that you want.

Rene
