Sampling error - Initial evaluation of model at starting point failed!

I’m just trying to carry out a bayesian regression and I keep getting a sampling error. This is my model:

product_array = data_aggr_period_prod_BR[‘product’].unique()
for product in product_array:
# Get the prior Normal parameters
regression_results_loop = regression_results_BR[regression_results_BR[‘Product’]==product]
data_aggr_period_prod_loop = data_aggr_period_prod_BR[data_aggr_period_prod_BR[‘product’]==product]
slope_mean = regression_results_loop[[‘Slope’]].mean().values[0]
slope_std = regression_results_loop[[‘Slope’]].std().values[0]
intercept_mean = regression_results_loop[[‘Intercept’]].mean().values[0]
intercept_std = regression_results_loop[[‘Intercept’]].std().values[0]

# Create bayesian model
with pm.Model() as bayesian_model_prod6:
    slope = pm.Normal('slope', mu = slope_mean, sd = slope_std)
    intercept = pm.Normal('intercept', mu = intercept_mean, sd = intercept_mean)

    # Linear regression line
    mean = intercept + slope*data_aggr_period_prod_loop['x']

    # Describe the distribution of our conditional output
    y = pm.Normal('y', mu = mean, observed = data_aggr_period_prod_loop['y']) # Run the sampling using pymc3 for 100 samples
    trace_600 = pm.sample(100, return_inferencedata=True)

The sampling error is being produced from the line where I define trace_600. How could I fix this?

Try model.debug() and see if it helps.

Otherwise this seems like a typo?

    intercept = pm.Normal('intercept', mu = intercept_mean, sd = intercept_mean)

I imagine you want sd = intercept_std

Yes, it was a typo but now that I have changes that I got this:

SamplingError: Initial evaluation of model at starting point failed!
Starting values:
{‘slope’: array(0.00049181), ‘intercept’: array(0.80299521)}

Initial evaluation results:
slope -inf
intercept -inf
y -23.72
Name: Log-probability of test_point, dtype: float64

I will try the debug that you suggested

What is your slope_mean and slope_std values. Maybe they are too extreme and you are getting numerical issues.

my slope mean value is 0.0004918058105516407
and slope std is nan which is probably the problem

That is definitely bad :slight_smile: