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

Diminishing returns of external regressors #642

Closed
royrvd opened this issue Dec 7, 2021 Discussed in #635 · 2 comments
Closed

Diminishing returns of external regressors #642

royrvd opened this issue Dec 7, 2021 Discussed in #635 · 2 comments

Comments

@royrvd
Copy link

royrvd commented Dec 7, 2021

Discussed in #635

Originally posted by royrvd November 28, 2021
Hey Orbit team!

While trying to calculate the diminishing returns of each regressor from the demo using the following code:

def calc_regressor_diminishing_return(model, df, regressor):
    reg_max = df[regressor].max()
    reg_min = df[regressor].min()
    preds = []
    sample_df = df.iloc[[0]].copy()
    for i in np.linspace(reg_min, reg_max, num=50):
        sample_df[regressor] = i
        pred = np.exp(model.predict(sample_df)["prediction"].values[0])
        preds.append(pred)
    return preds

def plot_diminishing_returns(model, df, regressors):
    ncols = 2
    nrows = int(np.ceil(len(regressors) / 2))
    fig, axes = plt.subplots(figsize=(15, 15), ncols=ncols, nrows=nrows)
    for ax, reg in zip(axes.flatten(), regressors):
        diminishing_returns = calc_regressor_diminishing_return(model, df, reg)
        ax.plot(diminishing_returns)
        ax.set_title(reg)
    return fig

plot_diminishing_returns(ktr, rw_data, regressor_col)

I got non-monotonic curves. Does that make sense or could that be an error?

image

@edwinnglabs
Copy link
Collaborator

Hi @royrvd , if I understand correctly, you are performing some non-linear operation on the MCMC / Full Bayesian model prediction. I guess there are couple of sources you need to look into:

  1. you probably want to do a point estimate instead since full Bayesian prediction involves the quantile function which is not associative with non-linear operations; so the fix is to use the arg point_method='median'
  2. if you really want to use Full Bayesian, you should get the whole posterior distributions out and perform non-linear process first and then the quantile function. However, it may not solve the problem completely
  3. there could be randomness due to the seed in various call of MCMC prediction, chance is you need to fix the seed in order to iteratively call the prediction

Hope that makes sense!

@royrvd
Copy link
Author

royrvd commented Dec 9, 2021

I'll try it out, thanks!

@royrvd royrvd closed this as completed Dec 9, 2021
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

No branches or pull requests

2 participants