Skip to content

ENH: Add Learning Fair Representations (LFR) preprocessing algorithm #8 - #14

Open
divyanshbhai wants to merge 10 commits into
usarfoss:mainfrom
divyanshbhai:fix-issue-8
Open

ENH: Add Learning Fair Representations (LFR) preprocessing algorithm #8#14
divyanshbhai wants to merge 10 commits into
usarfoss:mainfrom
divyanshbhai:fix-issue-8

Conversation

@divyanshbhai

Copy link
Copy Markdown

Summary

Implements the Learning Fair Representations (LFR) preprocessing algorithm by Zemel et al. (2013) to address issue #8.

Changes Made

  • Core Algorithm: LearningFairRepresentations class in fairlearn.preprocessing
  • Unit Tests: Comprehensive test suite in test/unit/preprocessing/
  • Documentation: API reference and user guide integration
  • Example: Complete usage demonstration
  • Integration: Works with existing fairness testing framework

Key Features

  • Learns prototype-based fair representations for demographic parity
  • Dual usage: preprocessor or end-to-end classifier
  • Configurable parameters (k prototypes, loss weights)
  • Robust optimization with numerical stability

Validation

  • All tests pass
  • Successfully reduces demographic parity difference on synthetic data
  • Compatible with scikit-learn TransformerMixin interface
  • Integrated with Fairlearn fairness metrics

Files Changed

  • fairlearn/preprocessing/_learning_fair_representations.py (new)
  • fairlearn/preprocessing/__init__.py (updated exports)
  • test/unit/preprocessing/test_learning_fair_representations.py (new)
  • test/unit/preprocessing/test_learning_fair_representations_predict.py (new)
  • test/unit/preprocessing/test_preprocessing_fairness.py (updated)
  • docs/user_guide/mitigation/preprocessing.rst (updated)
  • docs/user_guide/mitigation/index.rst (updated)
  • examples/plot_learning_fair_representations.py (new)

Closes #8

Divyansh added 10 commits October 15, 2025 19:11
- Create _optimized_preprocessing.py with class skeleton
- Add OptimizedPreprocessing to preprocessing module exports
- Implement basic fit/transform interface following sklearn conventions
- Add comprehensive docstring with algorithm description and references

Part of implementing Calmon et al. algorithm for issue usarfoss#9
- Add probabilistic transformation learning via constrained optimization
- Implement feature discretization for tractable optimization
- Add demographic parity constraints with epsilon tolerance
- Implement distortion minimization objective function
- Add probabilistic data transformation with noise injection

Follows Calmon et al. methodology for discrimination prevention
- Create test_optimized_preprocessing.py with 15+ test cases
- Test initialization, fit/transform functionality, and edge cases
- Add parameter validation and input validation
- Test reproducibility, different epsilon values, and sklearn compatibility
- Verify error handling for invalid inputs and parameters

Ensures robust implementation following fairlearn testing standards
- Add detailed section in preprocessing.rst user guide
- Include mathematical formulation and algorithm description
- Add practical usage example with synthetic data
- Include Calmon et al. reference in bibliography
- Document fairness-utility trade-off via epsilon parameter

Completes documentation requirements for issue usarfoss#9
…mentation

- Implement LearningFairRepresentations class based on Zemel et al. (2013)
- Add comprehensive unit tests covering various scenarios
- Update preprocessing module exports to include LFR
- Algorithm learns k prototypes with fairness constraints for demographic parity
…ation

- Add parameter validation for k, loss weights, and max_iter
- Improve gradient computation with numerical stability
- Add gradient clipping to prevent optimization instability
- Add comprehensive documentation to user guide
- Update mitigation algorithms table to include LFR
- Enhanced test coverage for parameter validation
- Add LearningFairRepresentations to preprocessing fairness tests
- Update test fixtures to handle LFR's sensitive_features requirement
- Fix dataset splitting to properly handle sensitive features for all algorithms
- Ensure LFR works with existing fairness metrics and evaluation pipeline
- Add predict() method for binary classification
- Add predict_proba() method for probability predictions
- Ensure consistency between predict and predict_proba methods
- Add comprehensive tests for prediction functionality
- Methods only available when algorithm fitted with target labels
- Enables LFR to be used as both preprocessor and end-to-end classifier
- Create detailed example demonstrating LFR algorithm usage
- Show comparison between original model, LFR+LogReg, and LFR direct prediction
- Include fairness metrics evaluation and transformation analysis
- Make matplotlib optional for environments without visualization support
- Demonstrate successful demographic parity improvement on synthetic data
- Document complete implementation of GitHub issue usarfoss#8
- List all delivered components and features
- Show validation results and commit history
- Confirm all requirements fulfilled
- Ready for production use and contribution points
This was referenced Oct 15, 2025
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.

ENH Add pre-processing algorithm "Learning Fair Representations" by Zemel et al.

1 participant