abidlabs / contrastive

Contrastive PCA
MIT License
199 stars 47 forks source link

How to get the top cPCA components? #5

Closed vyraun closed 6 years ago

vyraun commented 6 years ago

Hi, I am trying to get the top cPCA components, is there a way to get that directly without tinkering with the code?

mdl = CPCA(n_components=2) projected_data = mdl.fit_transform(a, b, plot=True)

i.e. What are the top cPCA components that explain a, b's differences?

Thanks!

abidlabs commented 6 years ago

Hi @vyraun, great question! I should point out that the top cPCA components (referred to as cPCs) are different for each value of alpha, since the cPCs are the result of finding the eigenvectors of A-alpha B. If you have a specific value of alpha for which you'd like to get the components (e.g. based on the plots you've generated), then the easiest way would probably be to do PCA (using sklearn's excellent library) on the matrix generated by mdl.fg_cov() - alphamdl.bg_cov() and take the top components.

vyraun commented 6 years ago

@abidlabs that will work, Thanks!