Skip to content

warn when n_factors exceeds number of features#149

Open
Qayad-Ali wants to merge 1 commit into
EducationalTestingService:mainfrom
Qayad-Ali:warn-n-factors-exceeds-features
Open

warn when n_factors exceeds number of features#149
Qayad-Ali wants to merge 1 commit into
EducationalTestingService:mainfrom
Qayad-Ali:warn-n-factors-exceeds-features

Conversation

@Qayad-Ali

Copy link
Copy Markdown

Summary

FactorAnalyzer.fit caps the number of factors when n_factors is greater than the number of features — it returns a truncated loadings matrix with no indication to the user:

import numpy as np
from factor_analyzer import FactorAnalyzer

X = np.random.default_rng(0).normal(size=(200, 6))
fa = FactorAnalyzer(n_factors=10, rotation=None).fit(X)
print(fa.loadings_.shape)   # (6, 6) — 10 requested, silently reduced to 6, no warning

In factor analysis the number of factors can't exceed the number of observed variables, so requesting more is mostly always a mistake. This gives a UserWarning in that case — consistent with the existing warning when the number of factors is constrained by the sample size.

Changes

  • FactorAnalyzer.fit: warn when n_factors > n_features.
  • Added a test in tests/test_factor_analyzer.py.

No change to results for valid inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant