Skip to content

Fix MFA column-output labels for categorical/MultiIndex groups (#242) - #243

Merged
MaxHalford merged 1 commit into
masterfrom
fix/mfa-column-output-labels-242
Jun 30, 2026
Merged

Fix MFA column-output labels for categorical/MultiIndex groups (#242)#243
MaxHalford merged 1 commit into
masterfrom
fix/mfa-column-output-labels-242

Conversation

@MaxHalford

Copy link
Copy Markdown
Owner

Fixes #242.

Problem

For an MFA with categorical groups and MultiIndex columns, the column outputs had two issues the reporter flagged:

  1. Ugly categorical labels. pandas.get_dummies stringified the tuple column label as the one-hot prefix, producing "('treatment', 'arm')__control" instead of something structured.
  2. Flat Index of mixed tuples/strings, inconsistent with the partial outputs (which use a MultiIndex).

I also found a latent third bug: the MFA.column_coordinates(X) method raised AttributeError because it delegated to a non-existent PCA.column_coordinates.

Fix

  • Column outputs (column_coordinates_, column_correlations, column_contributions_, column_cosine_similarities_) now use a clean 2-level (group, variable) MultiIndex:
    • numerical → (group, var) e.g. ("chemical", "shared")
    • categorical → (group, "var__category") e.g. ("treatment", "arm__control"), matching MCA's existing var__category convention.
  • MFA.column_coordinates(X) now raises an explicit NotImplementedError. A FactoMineR-matching implementation requires category barycenters (quali.var$coord) rather than the indicator-column loadings exposed by column_coordinates_, and is left for a follow-up.

Tests

  • test_column_coordinates_index (in TestMFACategorical, runs across all supplementary-row / supplementary-group combinations): asserts the 2-level MultiIndex, clean var__category labels, no stringified tuples, and that derived outputs share the index.
  • test_column_coordinates_method_not_implemented: the method raises NotImplementedError.
  • test_column_coordinates_labels_issue_242: standalone reproduction of the issue's exact example.

Full suite passes (674 passed, 2 skipped); ty and ruff are clean.

Bumps version to 0.20.1.

🤖 Generated with Claude Code

Column outputs now use a clean 2-level (group, variable) MultiIndex,
consistent with the partial outputs. Categorical indicator labels read
(group, "var__category") instead of the stringified
"('group', 'var')__category" prefix that pandas.get_dummies produced from
tuple column labels.

The X-taking MFA.column_coordinates method previously raised AttributeError
(it delegated to a non-existent PCA.column_coordinates); it now raises an
explicit NotImplementedError. A FactoMineR-matching implementation needs
category barycenters (quali.var$coord) and is left for a follow-up.

Bumps version to 0.20.1.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@MaxHalford
MaxHalford merged commit 2ba9b0d into master Jun 30, 2026
4 checks passed
@MaxHalford
MaxHalford deleted the fix/mfa-column-output-labels-242 branch June 30, 2026 20:24
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.

BUG: index labels in column outputs for MFA with categorical data

1 participant