PCA in scikit-learn has an attribute called "explained_variance" which captures the variance explained by each component. I don't see a similar thing like this for FactorAnalysis in scikit-learn. How can I compute the variance explained by each component for Factor Analysis?
Here is how you can do it :
First get the components matrix and the noise variance once you have performed factor analysis,let fa be your fitted model
m = fa.components_
n = fa.noise_variance_
Square this matrix
m1 = m**2
Compute the sum of each of the columns of m1
m2 = np.sum(m1,axis=1)
Now the %variance explained by the first factor will be
pvar1 = (100*m2[0])/np.sum(m2)
similarly, second factor
pvar2 = (100*m2[1])/np.sum(m2)
However, there is also a variance explained by the noise component, if you account for that in your variance explained you will need to compute
pvar1_with_noise = (100*m2[0])/(np.sum(m2)+np.sum(n))
pvar2_with_noise = (100*m2[1])/(np.sum(m2)+np.sum(n))
and so on. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With