Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Factor Analysis in sklearn: Explained Variance

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?

like image 619
vkmv Avatar asked Jun 12 '26 05:06

vkmv


1 Answers

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.

like image 155
Gaurav Dhama Avatar answered Jun 14 '26 20:06

Gaurav Dhama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!