Skip to content

Error Plotter for visualizing metrics with error ranges - #857

Merged
riedgar-ms merged 46 commits into
fairlearn:mainfrom
alexquach:main
Feb 28, 2022
Merged

riedgar-ms merged 46 commits into
fairlearn:mainfrom
alexquach:main

Conversation

@alexquach

@alexquach alexquach commented Jun 8, 2021 •

Copy link
Copy Markdown
Contributor

Add a plotting method (along with example code) which shows estimated error bars for MetricFrame.

Related to #235

@alexquach

Copy link
Copy Markdown
Contributor Author

#235

@romanlutz romanlutz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I added a bunch of comments, although it's clear you're aware of the additional TODOs that remain at the moment.

I think this is a fine approach. In general, we expect people to add tests for new functionality, which perhaps isn't possible here since it's plotting. I've written some matplotlib tests myself but they don't work on all operating systems and are deactivated for that reason. The example will run on every PR, so that's something. I would appreciate if you could add

  • a summary to the user guide's "assessment" section
  • a note to CHANGES.md
  • optional: if you like you can add your name to AUTHORS.md 🙂

Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread fairlearn/metrics/_error_plotter.py Resolved
Comment thread fairlearn/metrics/_error_plotter.py Resolved
Comment thread fairlearn/metrics/_error_plotter.py Resolved
Comment thread fairlearn/metrics/_error_plotter.py Resolved
Comment thread fairlearn/metrics/_error_plotter.py Resolved
Comment thread fairlearn/metrics/_error_plotter.py Resolved
Comment thread examples/plot_metrics_with_error.py Outdated
return error


def wilson(p, n, digits=digits, z=z_score):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would these not be useful to define in fairlearn.metrics?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some of them (like this Wilson bound).... really they belong somewhere like sklearn, though

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then shall we perhaps talk to sklearn folks about contributing it there? I don't mind having it here temporarily until sklearn has a release out with it, of course. @adrinjalali any thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This sounds more like something that would be on either scipy.stats or statsmodels (which already has a function called proportion_confint)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great! Do we want to use the ones that are available from elsewhere then and only redefine the ones that don't exist yet?

@adrinjalali adrinjalali Jul 21, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I second roman here, especially if they're in scipy.

Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Outdated
return (round(lower_bound, digits), round(upper_bound, digits))


def compute_error_metric(metric_value, sample_size, z_score):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note for any future documentation: this formula assumes that the metric is a proportion, which makes sense for most classification metrics but maybe not for different types of metrics, e.g., for mean_prediction in regression problems you'd need to use a confidence interval for the mean.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I expect a lively discussion about how to document these and present the examples :-)

Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Outdated
return error


def wilson(p, n, digits=digits, z=z_score):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then shall we perhaps talk to sklearn folks about contributing it there? I don't mind having it here temporarily until sklearn has a release out with it, of course. @adrinjalali any thoughts?

Comment thread examples/plot_metrics_with_error.py Resolved

@riedgar-ms riedgar-ms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the update!

Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved

@riedgar-ms riedgar-ms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for updating. @hildeweerts @michaelamoako @MiroDudik what do you think of the updated API? It would be great to get that agreed, so that @alexquach can fill out tests etc.

Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread fairlearn/experimental/__init__.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved

@riedgar-ms riedgar-ms left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the updates!

Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread examples/plot_metrics_with_error.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved

@MiroDudik MiroDudik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is very close! Just a couple of small tweaks requested.

Comment thread fairlearn/metrics/_plotter.py Outdated
error_labels_fontsize: int = 8,
error_labels_color: str = "black",
error_labels_ha: str = "center",
legend_label: str = "95% CI",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should change the argument name from legend_label to error_labels_legend (for consistency with other arguments). Also, the default should be None corresponding to no legend being displayed. We shouldn't assume that the provided confidence intervals are 95%.

As an alternative to the default of None, we could also default to "conf. intervals", I think that "CI" is way too cryptic. I'm personally slightly in favor of None, but I don't mind "conf. interval" since that matches the name of the provided argument. (Tagging @hildeweerts since she mentioned this before.)

Comment thread fairlearn/metrics/_plotter.py Resolved

@riedgar-ms riedgar-ms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@MiroDudik I think I've updated to reflect your key points (am waiting on the builds, though)

Comment thread fairlearn/metrics/_plotter.py Resolved
@riedgar-ms
riedgar-ms requested a review from MiroDudik February 18, 2022 14:52
@riedgar-ms

Copy link
Copy Markdown
Member

Ping.... @MiroDudik .....

@riedgar-ms

Copy link
Copy Markdown
Member

@MiroDudik ?

Comment thread fairlearn/metrics/_plotter.py Resolved
Comment thread fairlearn/metrics/_plotter.py Resolved
@riedgar-ms
riedgar-ms requested a review from MiroDudik February 28, 2022 19:27
@riedgar-ms
riedgar-ms merged commit 37d20a8 into fairlearn:main Feb 28, 2022
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.

6 participants