Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] FIX make ThresholdOptimizer sklearn compatible #342

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions fairlearn/postprocessing/_threshold_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ class ThresholdOptimizer(BaseEstimator, ClassifierMixin, MetaEstimatorMixin):
:type: bool, default=False
"""

def __init__(self, *, estimator=None,
def __init__(self, estimator=None, *,
constraints=DEMOGRAPHIC_PARITY, grid_size=1000, flip=True,
prefit=False):
self.grid_size = grid_size
self.flip = flip
self.post_processed_predictor_by_sensitive_feature = None
self.constraints = constraints
self.estimator = estimator
self.prefit = prefit
Expand Down
7 changes: 7 additions & 0 deletions test/unit/postprocessing/test_threshold_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from copy import deepcopy
import numpy as np
import pytest
from sklearn.utils.estimator_checks import parametrize_with_checks

from fairlearn.postprocessing._constants import DEMOGRAPHIC_PARITY, EQUALIZED_ODDS
from fairlearn._input_validation import \
(_MESSAGE_Y_NONE,
Expand Down Expand Up @@ -443,3 +445,8 @@ def create_adjusted_predictor(threshold_optimization_method, sensitive_features,

return lambda sensitive_features_, scores: _vectorized_prediction(
post_processed_predictor_by_sensitive_feature, sensitive_features_, scores)


@parametrize_with_checks([ThresholdOptimizer])
def test_sklearn_compatibility(estimator, check):
check(estimator)