Interpret.plot_predictions with transformed variables #821
-
Hey there! I had a question regarding the use of bmb.intrepret when the model includes transformations (scale(X), log(X) or both). By default Bambi seems to plot the covariable back into its original scale/values, while the prediction in its transformed scale. Is there a way to control this either way? Say, keep Y(X) in its original scale, or plot it as a function of the transformed X? The latter is manageable by adding a new column in my dataframe, but the former isn't so direct. More importantly, I had a case come up where I wanted to normalize log(x). scale(log(x)) seems to work for the inference model, but then bmb.interpret.plot_predictions fails/returns an error. Is it something related to my input or a limitation of the function? Attached is a short Jupyter notebook with a quick example if it helps. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
Hey @SanBertero thanks for the question and notebook.
To keep # model_5.formula = Formula('scale(Y) ~ scale(X)')
y_mean = np.mean(Y)
y_std = np.std(Y)
inv_transform = lambda x: x*y_std + y_mean
fig, ax = bmb.interpret.plot_predictions(
model_5,results_5,
'X',
pps=True,
prob=0.9,
transforms={"scale(Y)": inv_transform}
)
What version of Bambi are you using? We pushed changes to address this bug, but I am not sure it is in the latest release. |
Beta Was this translation helpful? Give feedback.
Hey @SanBertero thanks for the question and notebook.
To keep
Y
on its original scale, you could pass an inverse transform function to thetransforms
parameter, e.g.