You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add Varimax rotation for Factor Analysis and PCA #2688
Rotation methods such as Varimax should be added to PCA. It helps identify the factors that make up the components and would be useful in analysis of data.
it's indeed a well known method that can offer some insights on data. A
gist with a good illustrative example would be a start to see if it's
conclusive. If so, a PR can be started.
This is already an old topic, but FA needs rotation methods and it is still not implemented in scikit learn. Are there any concrete plans to implement the code above?
Examples and documentation are included in the factor rotation code I put on Github. Since a whole bunch of ration methods are supported, it is a bit more code though.
@mvds314 sadly I wouldn't know how to rewrite your code for scikit_learn - but I would also be very happy if this feature became available. If you need any sort of testing I can try to help.
@amueller: If I understand you correctly, the example shows how the code works, but you want to understand what happens. This is explained in detail in docstring of the rotate factors function. This file also contains some references to papers. The short summary is that the factors are rotated according to some criterion. The criterion that is minimized is explained in the docstring. The minimization procedure itself is numerical and the the algorithm for this is explained in the references also mentioned in the docstring.
@jona-sassenhagen I have been able to clone the master branch of Scikit-learn from your repository and installed on my machine but the rotation option from FactorAnalysis is not there.
Do I need to do anything else to add that functionality? Can you confirm if the version of the FactorAnalysis function with rotation is in the master branch?
The drawbacks of using an orthogonal rotation (such as Varimax) after a PCA are :
We lose the variance-maximizing properties of PCA (optimal variance explanation in the first components).
This property is essential to extract the top k components.
However, once the components are extracted, this property becomes much less relevant.
The rotation can be applied after the component extraction (the amount of explained variance will remain the same).
So this point is not very troublesome.
Activity
agramfort commentedon Dec 25, 2013
it's indeed a well known method that can offer some insights on data. A
gist with a good illustrative example would be a start to see if it's
conclusive. If so, a PR can be started.
Can you draft the gist?
dengemann commentedon Dec 25, 2013
Here's a MATLAB implementation, btw.
http://www.stat.ufl.edu/~tpark/Research/varimaxTP.m
agramfort commentedon Dec 25, 2013
another one:
https://code.google.com/p/fieldtrip/source/browse/trunk/external/eeglab/varimax.m
dfrusdn commentedon Dec 26, 2013
Here it is in R:
http://stat.ethz.ch/R-manual/R-patched/library/stats/html/varimax.html
I would like to help but I am not very experienced in programming
dengemann commentedon Dec 26, 2013
Okay, I'm going to take a look.
rossfadely commentedon Jan 15, 2014
Here is a short bit of python that returns the rotation matrix for varimax and quartimax:
https://github.com/rossfadely/consomme/blob/master/consomme/rotate_factor.py
mvds314 commentedon Mar 1, 2016
I recently put some code on Github for factor ration under a BSD license.
robkoper commentedon Apr 30, 2016
This is already an old topic, but FA needs rotation methods and it is still not implemented in scikit learn. Are there any concrete plans to implement the code above?
agramfort commentedon Apr 30, 2016
mvds314 commentedon Apr 30, 2016
Examples and documentation are included in the factor rotation code I put on Github. Since a whole bunch of ration methods are supported, it is a bit more code though.
TheChymera commentedon Jun 20, 2016
@mvds314 sadly I wouldn't know how to rewrite your code for
scikit_learn- but I would also be very happy if this feature became available. If you need any sort of testing I can try to help.amueller commentedon Oct 11, 2016
Should this be an option of PCA and FA? (I guess ICA wouldn't make sense).
Or should this be a stand-alone model?
@mvds314 your example doesn't really explain what's happening. I think we're still open to a more full-fledged example.
mvds314 commentedon Oct 12, 2016
@amueller: If I understand you correctly, the example shows how the code works, but you want to understand what happens. This is explained in detail in docstring of the rotate factors function. This file also contains some references to papers. The short summary is that the factors are rotated according to some criterion. The criterion that is minimized is explained in the docstring. The minimization procedure itself is numerical and the the algorithm for this is explained in the references also mentioned in the docstring.
I hope this helps!
robkoper commentedon Oct 12, 2016
@amueller 'Should this be an option of PCA and FA? '
I would prefer the code to be available to both, although there is a debate about the question whether the result of rotated PCA is still PCA. But this is largely a dispute about the definitions of PCA and FA. See for more info this post: http://stats.stackexchange.com/questions/612/is-pca-followed-by-a-rotation-such-as-varimax-still-pca
22 remaining items
Akumenyi commentedon Sep 26, 2018
@jona-sassenhagen sorry for the lack of clarity; i get a type error;
TypeError Traceback (most recent call last)
for ax, method in zip(axes, (None, 'varimax')):
----> fa = FactorAnalysis(n_components=n_comps, method= 'varimax').fit(X)
components = fa.components_.T
TypeError: init() got an unexpected keyword argument 'method'
jona-sassenhagen commentedon Sep 26, 2018
Ok, that's cause the code in #11064 is not yet merged. You could pull that branch and it should work.
Akumenyi commentedon Sep 26, 2018
@jona-sassenhagen apologies. how do I do that?
jona-sassenhagen commentedon Sep 26, 2018
Sorry, I'm not competent to give you an intro to git. You will have to familiarise yourself with git a bit by your own. Then purge your current sklearn, install sklearn from GitHub, add my repo, and do this: https://stackoverflow.com/questions/1709177/git-pull-a-certain-branch-from-github
Akumenyi commentedon Sep 27, 2018
@jona-sassenhagen thanks for the help.
Akumenyi commentedon Oct 1, 2018
@jona-sassenhagen I have been able to clone the master branch of Scikit-learn from your repository and installed on my machine but the rotation option from FactorAnalysis is not there.
Do I need to do anything else to add that functionality? Can you confirm if the version of the FactorAnalysis function with rotation is in the master branch?
Thanks
Kwesi
jona-sassenhagen commentedon Oct 1, 2018
It's not in the master branch - it's in
jona-sassenhagen:varimaxjona-sassenhagen commentedon Oct 1, 2018
see here: #11064
Akumenyi commentedon Oct 1, 2018
@jona-sassenhagen Thanks! I have finally been able to get to work.
For future beginners of git;
All I did was to install scikit-learn from @jona-sassenhagen repository then
git checkout -b origin/varimax and
python setup.py install
Cheers!
ptgoff commentedon May 19, 2021
Here is an excellent paper (2020) that addresses the need for rotation (varimax) following PCA. https://arxiv.org/abs/2004.05387
tatopane commentedon Oct 21, 2021
Hi, is there a reason why this was implemented in FA but not in PCA, apart from the comment above?
I need to do PCA and then varimax, is there a known workaround? (I googled a lot but couldn't find the answer)
Thanks
huaracheguarache commentedon Nov 24, 2022
I would also really like to see this implemented for PCA.
keyber commentedon May 4, 2024
The drawbacks of using an orthogonal rotation (such as Varimax) after a PCA are :
We lose the variance-maximizing properties of PCA (optimal variance explanation in the first components).
This property is essential to extract the top k components.
However, once the components are extracted, this property becomes much less relevant.
The rotation can be applied after the component extraction (the amount of explained variance will remain the same).
So this point is not very troublesome.
The axes are not orthogonal anymore
Even though the axes are initially orthogonal and the Varimax rotation is also orthogonal, the resulting axes are not (it is not the axes that are rotated by the Varimax rotation https://stats.stackexchange.com/a/136936).
If I understand correctly, this means that the features we obtain could be correlated.
Another alternative would be to use SparsePCA , but SparsePCA also suffers from non-orthogonality.