-
-
Notifications
You must be signed in to change notification settings - Fork 127
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
plot_cap
default args. not working for categorical regression
#673
Conversation
The legend is now able to show the class / outcome name when the data type of the response variable is categorical. If the response variable is categorical, then the default Using the same code as above: However, now we have the problem when specifying |
@@ -262,12 +266,17 @@ def plot_cap( | |||
def _plot_cap_numeric(covariates, cap_data, y_hat_mean, y_hat_bounds, transforms, legend, axes): | |||
main = covariates.get("horizontal") | |||
transform_main = transforms.get(main, identity) | |||
y_hat_bounds_dim = y_hat_bounds.ndim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we call it y_ndim
or y_hat_bounds_ndim
?
@GStechschulte thanks for the great PR, as always. To your last point "To solve this, we would also need to override the color each time in the loop or set a default colour mapping based on the unique class names (which is still problematic since the color is set and plotted sequentially in the for loop). Any thoughts on this?" I would say one approach would be to allow users to map the dimension of the response to the color or panel layer of the plot. By default, the color is mapped to the level of the response, when there are multiple response levels. But it can be overridden as you did in your example, and then it's up to the user to override things in a meaningful way. For example, I think it would make sense to ask for the response level to be mapped to the panel, in the case you want one panel per level. The question then is how this is specified in the So in your example one could be able to do fig, ax = plot_cap(
model=model,
idata=idata,
covariates={"horizontal": "length", "color": "sex", "panel": "choice_dim"},
fig_kwargs={"figsize": (16, 5), "sharey": True},
pps=False
); or fig, ax = plot_cap(
model=model,
idata=idata,
covariates={"horizontal": "length", "color": "choice_dim", "panel": "sex"},
fig_kwargs={"figsize": (16, 5), "sharey": True},
pps=False
); And by default the behavior would be as if you pass Do you think this makes sense? I'm not married to it of course. |
I will circle back to this when the core functionality of |
I agree with the approach. Let's do one at at time. Thanks for being explicit by the way :) |
@GStechschulte after all the magic in #684, is this still needed? |
@tomicapretto I believe so. I did not change any of the code in |
Closing as this PR will no longer resolve the issue. See updated issue #723 |
This draft PR addresses issue #669 that adds additional logic in$K$ outcome classes.
_plot_cap_numeric()
of theplot_cap
function to support indexing of N-dimensionaly_hat_bounds
to ensureax.fill_between()
works forBefore plotting begins in
_plot_cap_numeric()
, an additional variabley_hat_bounds_dim = y_hat_bounds.ndim
is created to identify the number of dimensions. Then, when plotting is performed, an if / else statement is used to determine ifndims > 2
. If yes, then we loop through each dimension and plotax.fill_between()
, else no for loop is needed.The added logic allows$K$ classes, but it requires copy and paste of the if / else statement for each
ax.fill_between()
to scale tocolor
panel
combination inside of_plot_cap_numeric
. Which in my opinion is kind of ugly and doesn't adhere to DRY. But it works.Below are a few examples. I also identified that the class names are not specified in the legend due to the fact that the legend currently only looks in the covariates for the unique names.
To Do:
See there is no legend for class names. Making it hard to distinguish the lines.
Again, there is no legend for class names. The legend correctly identifies the sex, but it would be more informative if the title was kept to the sex type and the legend indicated the class.