Skip to content

Supporting count as a metric #737

Closed
Closed

Description

@adrinjalali

It's desired to know the number of data points in each group when working with MetricFrame, and that can be achieved by passing a function which returns the length of its input. For instance:

# report the above scores in a table.
from fairlearn.metrics import MetricFrame
import sklearn.metrics as skm
y_pred = np.asarray(df.y_pred).astype(float)
y_true = np.asarray(df.FraudLabel == "true").astype(int)
multi_metric = MetricFrame({
    'average precision':skm.average_precision_score,
    'roc-auc': skm.roc_auc_score,
    'count': lambda x, y: len(x)},
    y_true, y_pred,
    sensitive_features=df.gender)
multi_metric.by_group

We don't necessarily need to change anything in the code or API for this, but we should document it in the user guide and/or the API reference to let people know how it can be done.

Activity

  1. romanlutz commented on Apr 9, 2021

    @romanlutz
    Member

    I like this a lot. The lambda x, y: len(x) isn't super straightforward if you're not familiar with how to write a metric function. Should we just define the count function like we did with selection_rate so that people can import it and pass it without having to write the code themselves?

    Totally agree on documenting this. I guess the tasks here would be

    • to look at the user guide of MetricFrame and add that new count metric wherever we have 2 or more metrics passed to the MetricFrame, and write a short sentence or two on what this does (i.e., "show the number of people in the corresponding group")
    • to look through notebooks and add count whenever we have a MetricFrame.
  2. hildeweerts commented on Apr 12, 2021

    @hildeweerts
    Contributor

    I like the convenience of a separate count function, it makes it more beginner friendly I think. Do we need to open a separate issue for that?

  3. adrinjalali commented on Apr 12, 2021

    @adrinjalali
    MemberAuthor

    I think the same issue/pr could do both the doc and the function.

  4. MiroDudik commented on Apr 16, 2021

    @MiroDudik
    Member

    To clarify the count function proposal. I'm assuming we're just talking about adding fairlearn.metrics.count, but not doing anything with the MetricFrame API right?

  5. adrinjalali commented on Apr 17, 2021

    @adrinjalali
    MemberAuthor

    To clarify the count function proposal. I'm assuming we're just talking about adding fairlearn.metrics.count, but not doing anything with the MetricFrame API right?

    Correct :)

  6. vamsidesu5 commented on Apr 22, 2021

    @vamsidesu5
    Contributor

    Hey I can take this issue up!

  7. adrinjalali commented on Apr 23, 2021

    @adrinjalali
    MemberAuthor

    Sure, it's yours @vamsidesu5

  8. stephenrobic commented on May 17, 2021

    @stephenrobic
    Contributor

    I will begin working on this issue now. Thanks for your guidance @romanlutz

  9. romanlutz commented on May 17, 2021

    @romanlutz
    Member

    Thanks @stephenrobic ! @vamsidesu5 let me know if you want to do any other issues! I'd be happy to find you something.

  10. vamsidesu5 commented on May 18, 2021

    @vamsidesu5
    Contributor

    @romanlutz Hi - I was very busy the past 2 weeks and wasn't able to contribute. So sorry! Would you be able to find me another issue that would be interesting to work on?

  11. romanlutz commented on May 28, 2021

    @romanlutz
    Member

    Closing since @stephenrobic 's PR #812 was merged a week ago.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions