How to calculate FactorAnalysis scores using Python (scikit-learn)?
Seems that I figured out how to get scores.
from sklearn import decomposition, preprocessing
import numpy as np
data = np.genfromtxt('rangir_test.csv', delimiter=',')
data = data[~np.isnan(data).any(axis=1)]
data_normal = preprocessing.scale(data)
fa = decomposition.FactorAnalysis(n_components = 1)
fa.fit(data_normal)
for score in fa.score_samples(data_normal):
print score
Unfortunately the output (see below) is very different to one from factanal()
. Any advises on decomposition.FactorAnalysis()
will be appreciated.
Scikit-learn scores output:
-69.8587183816
-116.353511148
-24.1529840248
-36.5366398005
-7.87165586175
-24.9012815104
-23.9148486368
-10.047780535
-4.03376369723
-7.07428842783
-7.44222705099
-6.25705487929
-13.2313513762
-13.3253819521
-9.23993173528
-7.141616656
-5.57915693405
-6.82400483045
-15.0906961724
-3.37447211233
-5.41032267015
-5.75224753811
-19.7230390792
-6.75268922909
-4.04911793705
-10.6062761691
-3.17417070498
-9.95916350005
-3.25893428094
-3.88566777358
-3.30908856716
-3.58141292341
-3.90778368669
-4.01462493538
-11.6683969455
-5.30068548445
-24.3400870389
-7.66035331181
-13.8321672858
-8.93461397086
-17.4068326999
This is late but may be still interesting for OP or others who came here from google.
For everyone used to R factanal there is a python package available that wraps the R factanal function so that you can just call it from python with a pandas data frame like this:
from factanal.wrapper import factanal
fa_res = factanal(pdf, factors=4, scores='regression', rotation='promax',
verbose=True, return_dict=True)
More information: https://pypi.org/project/factanal/
Install with:
pip install factanal