How to create partial dependency plot?

I have 2 questions:
Similar to GAM, i would like to create partial dependency plots for the features. However, i am not completely sure how to create it.

For example, I have the the below model

with pm.Model() as model:
    alpha = pm.Normal('alpha', mu=0, sigma=10)
    beta1 = pm.Normal('beta1', mu=0, sigma=10)
    beta2 = pm.Normal('beta2', mu=0, sigma=10)
    mu = alpha + beta1 * X1.squeeze() + beta2 * X2.squeeze()
    sigma = pm.HalfNormal('sigma', sigma=1)
    y_obs = pm.Normal('y_obs', mu=mu, sigma=sigma, observed=y)

    trace = pm.sample(1000, tune=1000)

I want to create a pdp of of X1 on y and X2 on y?

Second, I would like to incorporate non linear effects on X2. How can i do that ? (similar to splines)

The pymc-bart package has a plot_pdp function that is geared towards BART models; I would look at that for hints on how to implement it more generally.

As for non-linear effects, perhaps the easiest way to do this is with a latent Gaussian process (or via BART, which would involve installing pymc-bart).

1 Like