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

plot predictions shape error with multinomial model #849

Open
GStechschulte opened this issue Sep 28, 2024 · 4 comments
Open

plot predictions shape error with multinomial model #849

GStechschulte opened this issue Sep 28, 2024 · 4 comments
Assignees

Comments

@GStechschulte
Copy link
Collaborator

@AlexAndorra raised a question/issue in the LB stats Slack. Posting here.


I'm doing something like this:

bmb.interpret.predictions(
    multinomial_model_bambi,
    idata_multinomial_bambi,
    conditional={
        "cat1": ["A", "B"],
        "name": ["name1", ..., "name10"],
    },
)

which works great, but then when trying to get the plot:

_, ax = bmb.interpret.plot_predictions(
    multinomial_model_bambi,
    idata_multinomial_bambi,
    conditional={
        "cat1": ["A", "B"],
        "name": ["name1", ..., "name10"],
    },
    subplot_kwargs={"main": "cat1", "group": "name", "panel": "name"},
);

that raises a weird error: ValueError: x and y must be the same size

@GStechschulte GStechschulte self-assigned this Sep 28, 2024
@GStechschulte
Copy link
Collaborator Author

GStechschulte commented Sep 29, 2024

This was my response to Alex.


I think you are getting the error because you are predicting multiple outcomes, and not passing the column name estimate_dim to subplot_kwargs. In your first code snippet where you print the summary dataframe, you will see that column.

The following should work:

_, ax = bmb.interpret.plot_predictions(
    multinomial_model_bambi,
    idata_multinomial_bambi,
    conditional={
        "cat1": ["A", "B"],
        "name": ["name1", ..., "name10"],
    },
    subplot_kwargs={"main": "cat1", "group": "name", "panel": "estimate_dim"},
);

What I noticed is that it is not obvious that you can pass the column name estimate_dim for model's predicting multiple outcomes, e.g multinomial or categorical. You will most likely want to plot each outcome as a hue or panel (facet), but if you do not know a priori that Bambi adds the column estimate_dim, then you will not pass it as a subplot kwarg.

@tomicapretto
Copy link
Collaborator

I'm not sure I understand if this is a bug or something we should document better 😅

@GStechschulte
Copy link
Collaborator Author

GStechschulte commented Sep 30, 2024

It's definitely something I would like to document better. From an interface point of view, I think the first plot in my comment above should render because: (1) the interpret.predictions successfully builds the data frame, and (2) none of ValueErrors for .interpret.plot_predictions are raised. So I think this is unexpected behaviour for the user point of view.

I will work on this :)

@tomicapretto
Copy link
Collaborator

@GStechschulte amazing, just ping me if you want review or help :)

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

No branches or pull requests

2 participants