Skip to content

Conversation

@itrajanovska
Copy link
Contributor

We need group wise risks to be able to assess the fairness of the assigned risks within groups
Successor of #48 implementing the computation of the group wise risks (as well as passing a custom ML model).

@itrajanovska
Copy link
Contributor Author

@MatteoGiomi After rebasing I deleted the branch because of some conflicts, and #52 was automatically closed.

Copy link
Member

@MatteoGiomi MatteoGiomi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this second contribution @itrajanovska, I left a few comments for your consideration.

Comment on lines 41 to 43
with pytest.raises(Exception) as runtime_error:
evaluate_inference_guesses(guesses=pd.Series(guesses), secrets=secrets, regression=False)
assert runtime_error.type is RuntimeError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pytest lets you check for specific exceptions, so that you don't need a separate assert for the exception type.

Suggested change
with pytest.raises(Exception) as runtime_error:
evaluate_inference_guesses(guesses=pd.Series(guesses), secrets=secrets, regression=False)
assert runtime_error.type is RuntimeError
with pytest.raises(RuntimeError) as runtime_error:
evaluate_inference_guesses(guesses=pd.Series(guesses), secrets=secrets, regression=False)

with pytest.raises(Exception) as runtime_error:
evaluate_inference_guesses(guesses=pd.Series(guesses), secrets=secrets, regression=False)
assert runtime_error.type is RuntimeError
assert "The predictions indices do not match the target indices" in str(runtime_error.value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move this inside the with pytest.raises context.

Comment on lines 42 to 43
samples = pd.read_csv(os.path.join(TEST_DIR_PATH, "datasets", fname), nrows=n_samples)
return samples.drop_duplicates(subset=deduplicate_on) if deduplicate_on else samples
Copy link
Member

@MatteoGiomi MatteoGiomi Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the number of returned samples is not always n_samples. To fix this one can read the whole dataframe, drop the duplicates, then return the first n_samples rows


def test_evaluator_not_evaluated():
df = get_adult("ori", n_samples=10)
df = get_adult("ori", deduplicate_on=None, n_samples=10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd stick to implicitly using the default in case no deduplication is needed.

Suggested change
df = get_adult("ori", deduplicate_on=None, n_samples=10)
df = get_adult("ori", n_samples=10)


group_wise = evaluator.risk_for_groups(confidence_level=0)

for _, results in group_wise.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test on the value of the risk? that way we are sure that all works e2e?


def test_mixed_type_kNN():
df = get_adult("ori", n_samples=10)
df = get_adult("ori", deduplicate_on=None, n_samples=10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as mentioned above:

Suggested change
df = get_adult("ori", deduplicate_on=None, n_samples=10)
df = get_adult("ori", n_samples=10)

@pytest.mark.parametrize("n_neighbors, n_queries", [(1, 10), (3, 5)])
def test_mixed_type_kNN_shape(n_neighbors, n_queries):
df = get_adult("ori", n_samples=10)
df = get_adult("ori", deduplicate_on=None, n_samples=10)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above.

@MatteoGiomi
Copy link
Member

hi @itrajanovska, I gave a final look and left a few minor comments. It's almost ready to go!

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.

2 participants