TypeError: range() missing 1 required positional arguments: "end"

Hi, I’m a beginner running Bayesian linear regression but keep failing at inference. could you pls help?

#get data 
DATA_URL = "https://d2hg8soec8ck9v.cloudfront.net/datasets/rugged_data.csv"
data = pd.read_csv(DATA_URL, encoding="ISO-8859-1")
df = data[["cont_africa", "rugged", "rgdppc_2000"]]
df = df[np.isfinite(df.rgdppc_2000)]
df["rgdppc_2000"] = np.log(df["rgdppc_2000"]) #log transform response

#create tensors 
data_in = torch.tensor(df[["cont_africa", "rugged",  "rgdppc_2000"]].values,
                        dtype=torch.float)

#slice tensors
is_cont_africa,ruggedness,lGDP = data_in[:, 0:1], data_in[:, 1:2], data_in[:, 2]

lGDP = data_in[:, 2:3] # maintain the dimensions

#define model 
def model_BayesLinReg(is_cont_africa, ruggedness, lGDP):
    n_obs = lGDP.shape[0]
    a = pyro.sample("a", dist.Normal(8., 1000.))
    b_a = pyro.sample("bA", dist.Normal(0., 1.))
    b_r = pyro.sample("bR", dist.Normal(0., 1.))
    b_ar = pyro.sample("bAR", dist.Normal(0., 1.))
    sigma = pyro.sample("sigma", dist.Uniform(0., 10.))
    
    mu = a + b_a * is_cont_africa + b_r * ruggedness + b_ar * is_cont_africa * ruggedness
    with pyro.plate("N", n_obs):
        y = pyro.sample("y", dist.Normal(mu, sigma), obs=lGDP)
    return y

#Define functio to train model
def train(model, guide, lr=0.005, n_steps=501):
    pyro.clear_param_store()
    adam_params = {"lr": lr}
    adam = pyro.optim.Adam(adam_params)
    svi = SVI(model, guide, adam, loss=Trace_ELBO())

    for step in range(n_steps):
        loss = svi.step(is_cont_africa, ruggedness, lGDP)
        if step % 50 == 0:
            print('[iter {}]  loss: {:.4f}'.format(step, loss))

autoguide_BayesLinReg = pyro.infer.autoguide.AutoDelta(model_BayesLinReg)
train(model = model_BayesLinReg, guide=autoguide_BayesLinReg)

error

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-69-8e9ce9be844d> in <cell line: 14>()
     12 
     13 autoguide_BayesLinReg = pyro.infer.autoguide.AutoDelta(model_BayesLinReg)
---> 14 train(model = model_BayesLinReg, guide=autoguide_BayesLinReg)

<ipython-input-69-8e9ce9be844d> in train(model, guide, lr, n_steps)
      6     svi = SVI(model, guide, adam, loss=Trace_ELBO())
      7 
----> 8     for step in range(n_steps):
      9         loss = svi.step(data)
     10         if step % 50 == 0:

TypeError: range() missing 1 required positional arguments: "end"

Hi. It’s hard to say without seeing the full code but my guess would be that you are overriding the built-in function range somewhere in your code.

Hi @ordabayev I already posted the full code. Bayesian linear regression where betas are Standard Guasian normals

I meant including all imports and anything before your posted code starts. The error you see is not related to Pyro because range is a built-in Python function. The fact that you see an error suggests that it might have been overridden (my guess) but I can’t know for sure without seeing the entire executable code. Also what version of Python and Pyro are you using?