Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
FactorAnalyzer
✓ from factor_analyzer import FactorAnalyzer
✗ from factor-analyzer import FactorAnalyzer
hyphen vs underscore
calculate_kmo
✓ from factor_analyzer.factor_analyzer import calculate_kmo
✗ from factor_analyzer import calculate_kmo
calculate_kmo is not exposed at top-level
calculate_bartlett_sphericity
✓ from factor_analyzer.factor_analyzer import calculate_bartlett_sphericity
Load data, check suitability, then fit FA with 3 factors and varimax rotation.
import pandas as pd
from factor_analyzer import FactorAnalyzer
from factor_analyzer.factor_analyzer import calculate_kmo, calculate_bartlett_sphericity
df = pd.read_csv('data.csv')
# Drop rows with missing values
df.dropna(inplace=True)
# Bartlett's test
chi2, p = calculate_bartlett_sphericity(df)
print('Bartlett p-value:', p)
# KMO
kmo_all, kmo_total = calculate_kmo(df)
print('KMO:', kmo_total)
# Factor analysis with 3 factors, varimax rotation
fa = FactorAnalyzer(rotation='varimax', n_factors=3)
fa.fit(df)
print('Loadings:\n', fa.loadings_)
Errors
Common errors & fixes
AttributeError: module 'factor_analyzer' has no attribute 'FactorAnalyzer'
Installed 'factor-analyzer' package but trying to import from 'factor-analyzer' with hyphen.
fixInstall correct package: pip install factor-analyzer ; import from factor_analyzer (underscore)
ValueError: n_features must be >= n_factors
Number of factors requested exceeds number of variables/columns in data.
fixReduce n_factors or increase variables.
AttributeError: 'FactorAnalyzer' object has no attribute 'loadings_'
Called .loadings_ before calling .fit().
fixCall fa.fit(df) then access fa.loadings_.
RuntimeError: Maximum Likelihood estimation failed to converge. Try increasing max_iter or adjusting tolerance.
ML extraction may not converge with default settings on difficult data.
fixSet max_iter=1000 or method='principal' (default is 'minres').
Upgrade
Version history
0.5.1latest on PyPI · released Feb 8, 2024
Audit
Dependencies
pandasrequiredDataFrame input
numpyrequirednumerical operations
scikit-learnrequiredPCA/Imputation
scipyrequiredoptimization