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

add densityplot #2741

Merged
merged 3 commits into from
Dec 11, 2017
Merged

add densityplot #2741

merged 3 commits into from
Dec 11, 2017

Conversation

aloctavodia
Copy link
Member

In the same spirit of #2736 a densityplot can be used to compare several traces/models (and also works for a single trace/model).

index

The KDE plots are truncated at their HPD interval, a point estimate (the mean by default) is represented using... a point. Each group of variables share the same scale (like in a traceplot and unlike a forestplot). At some point I though about implementing a ridgeline plot (AKA joyplot) but I am still not connived that those plots add too much value except for their coolness and fanciness.

Let me know if you think this could be a good addition to the PyMC3 plots, suggestions for alternative names are also welcomed.

@springcoil
Copy link
Contributor

springcoil commented Dec 3, 2017 via email

@aloctavodia
Copy link
Member Author

Thanks for the feedback @springcoil, just to add perspective the previous name was aplot :-)

@springcoil
Copy link
Contributor

springcoil commented Dec 3, 2017 via email

@ColCarroll
Copy link
Member

Thanks for including the sample! Can you show a snippet of code that would produce that? I am wondering in particular what m_0, m_1, m_2 are (and why the legend appears in only one figure).

@aloctavodia
Copy link
Member Author

Hi @ColCarroll

You will have to do: pm.densityplot(traces) to get that plot where traces is a list of traces (3 in this case). m_0, m_1, m_2 are the names of the 3 models/traces, these names are assigned automatically (the same with the colors) unless the user provides custom values. The legend appear only once to avoid redundancy/cluttering, you are comparing 3 models across all panels (variables), even when a model could not have all variables, like m_0 in this example that is missing the beta parameter.

This PR also adds a very simple usage example to an existing notebook of the pm.densityplot (and of the new forestplot)

@aloctavodia
Copy link
Member Author

Still not happy with this plot, another two options to help see the limits of the distributions

density_plot_03

density_plot_02

@springcoil
Copy link
Contributor

I like this last one. Do you think it's worth merging now, and iterating on it in the future.

@aloctavodia
Copy link
Member Author

Hi @springcoil, I need to commit the code for the last two figures and I should add a test. I could do it tomorrow.

I guess we don't need to choose between these 3 variations, they can be offered as different options, but which one should be the default one? The last one?

@ColCarroll what do you think?

@springcoil
Copy link
Contributor

Yeah a test would help. I think having three options is good, I think the last one should be the default one.

@aloctavodia
Copy link
Member Author

@springcoil thanks for the feedback! I will work on this.

@ColCarroll
Copy link
Member

Probably helpful to mimic the api of https://seaborn.pydata.org/examples/distplot_options.html , since it will be known to users already. In particular, they pass in kde_kwargs to allow shade=True or shade=False. Agree that the last one should probably be default -- it would be very tricky to set the alpha automatically for lots of densities to make them all visible.

Also agree that we can iterate on some of this after merging, so it isn't all on you!

@springcoil
Copy link
Contributor

Yeah I think shipping this, and then people experimenting with it will mean that the load isn't all on you.

@aloctavodia
Copy link
Member Author

Following your suggestions, @springcoil and @ColCarroll, I update the code and set a different default style. I changed the name of argument opacity to shade for internal consistency (this is the name we use for energyplot and kdeplot). BTW we use a float for the shade instead of a boolean, in that way we can avoid having one argument to turn on/off the shade and another one to set the alpha-level.

@springcoil
Copy link
Contributor

LGTM :)

@aloctavodia aloctavodia merged commit 75d1ce0 into pymc-devs:master Dec 11, 2017
@aloctavodia aloctavodia deleted the densityplot branch December 11, 2017 19:40
jordan-melendez pushed a commit to jordan-melendez/pymc3 that referenced this pull request Feb 6, 2018
* add densityplot

* add new default style and new options, add test and update release notes and example
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.

3 participants