# Weibull Regression with Covariates Sampling Error

**URL:** <https://discourse.pymc.io/t/weibull-regression-with-covariates-sampling-error/5269>\
**Category:** Questions\
**Created:** [June 13, 2020, 6:56pm UTC](https://discourse.pymc.io/t/weibull-regression-with-covariates-sampling-error/5269 "2020-06-13T18:56:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shashank\_gupta](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/shashank_gupta/32/2815_2.png) [@shashank\_gupta](https://discourse.pymc.io/u/shashank_gupta)\
**Post date:** [June 13, 2020, 6:56pm UTC](https://discourse.pymc.io/t/weibull-regression-with-covariates-sampling-error/5269/1 "2020-06-13T18:56:50Z")

</div>

Hi,

This is the first time I am trying out a Bayesian model, so please bear with me.

I am trying to perform Weibull Regression with some covariates.

I have Standardised the dataset and I am trying out the following model:

```
n_dim = training_data_norm.shape[1]
X_ = shared(training_data_norm)
with pm.Model() as model:

    # Priors for unknown model parameters
    k = pm.Gamma('k', alpha=10, beta=100)
    beta = pm.Normal('beta', mu=0, sd=0.001, shape=n_dim)
    #η = beta.dot(X_.T)
    # Expected value of lambda parameter
    lambda_obs = pm.Deterministic('beta_', \
         tt.nnet.relu(beta.dot(X_.T), alpha=0.001))
    

    # Likelihood (sampling distribution) of observations
    runningtime_obs = pm.Weibull('runningtime_obs', alpha=k, \
         beta=lambda_obs, observed=y_train) 

```

While sampling, using the following code:

```
with model:
    start = find_MAP()
    trace = pm.sample(500, start=start)

```

I am getting the following error:

```
Bad initial energy, check any log probabilities that are inf or -inf, nan or very small:
runningtime_obs -inf
SamplingError: Bad initial energy

```

Could anyone help me out in figuring the source of error.

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [June 14, 2020, 7:52pm UTC](https://discourse.pymc.io/t/weibull-regression-with-covariates-sampling-error/5269/2 "2020-06-14T19:52:21Z")

</div>

Hi,  
Thanks for your question. `Bad initial energy` error can have several causes. We have [an FAQ about this](https://discourse.pymc.io/t/frequently-asked-questions/74/5) that should help you.  
PyMCheers 🖖

---

<div class="post-metadata">

**Author:** ![shashank\_gupta](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/shashank_gupta/32/2815_2.png) [@shashank\_gupta](https://discourse.pymc.io/u/shashank_gupta)\
**Post date:** [June 15, 2020, 7:13am UTC](https://discourse.pymc.io/t/weibull-regression-with-covariates-sampling-error/5269/3 "2020-06-15T07:13:22Z")

</div>

Thanks for your reply.

Sorry, I should have checked FAQ first.

I suspected the ‘tt.nnet.relu’ was resulting in -inf.

Changed it to tt.log( 1+ exp(beta.dot(X\_T)). It was working fine.

I have another question regarding the range of the target variable. The current max value is very high.

Standardising it results in some negative values, which are not acceptable for Weibull distribution. Any recommendations on that?

Thanks,

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [June 15, 2020, 8:36am UTC](https://discourse.pymc.io/t/weibull-regression-with-covariates-sampling-error/5269/4 "2020-06-15T08:36:50Z")

</div>

Glad the FAQ could help 🙂  
I’m not familiar with the Weibull distribution, but there are a lot of ways to rescale your data besides the classical standardization. For instance, I think you could rescale your data on an interval, like [0, 1], and that way the sampler won’t have a hard time with the huge scale of the data.

---

<div class="post-metadata">

**Author:** ![shashank\_gupta](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/shashank_gupta/32/2815_2.png) [@shashank\_gupta](https://discourse.pymc.io/u/shashank_gupta)\
**Post date:** [June 15, 2020, 1:29pm UTC](https://discourse.pymc.io/t/weibull-regression-with-covariates-sampling-error/5269/5 "2020-06-15T13:29:48Z")

</div>

Thanks @AlexAndorra for your prompt replies.

Sure, I will try out rescaling and see if I get any better results.
