Registry / analytics / factor-analyzer

factor-analyzer

JSON →
library0.5.1pypypi✓ verified 85d ago

A factor analysis (FA) implementation in Python, providing exploratory factor analysis using principal component or maximum likelihood extraction with varimax/oblimin rotations. Version 0.5.1 supports Kaiser-Meyer-Olkin (KMO) test, Bartlett's test of sphericity, and parallel analysis. Released irregularly; last update 2022.

pip install factor-analyzer
INSTALL
IMPORT
SIG · FACTOR-ANALYZER
F
factor-analyzer
analyticspythonv0.5.1
harness data pending
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_)
Debug
Known issues
gotchaFactorAnalyzer.fit() silently drops rows with NaN. Always check for missing values first.
fix
Use df.dropna() before fitting.
affects: <0.5.0
gotchaRotation parameter must be lowercase: 'varimax', not 'Varimax'. Unknown rotation raises AttributeError.
fix
Use rotation='varimax', 'oblimin', or None.
affects: all
breakingIn v0.4.0, the method 'get_communalities()' was removed. Use fa.communalities_ attribute directly.
fix
Access fa.communalities_ after fit.
affects: >=0.4.0
gotchacalculate_kmo returns (kmo_per_variable, kmo_total). Many users forget the tuple unpacking.
fix
kmo_all, kmo_total = calculate_kmo(df)
affects: all
deprecatedThe module factor_analyzer.factor_analyzer is internal; top-level imports are preferred for FactorAnalyzer class.
fix
Use from factor_analyzer import FactorAnalyzer
affects: >=0.5.0
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.
fix
Install 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.
fix
Reduce n_factors or increase variables.
AttributeError: 'FactorAnalyzer' object has no attribute 'loadings_'
Called .loadings_ before calling .fit().
fix
Call 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.
fix
Set 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
Agent activity
28 hits · last 30 days
node
26
OpenAI (training)
1
Resources