In [1]:

```
import pandas as pd
import seaborn as sns
import torch
import pyro
import pyro.distributions as dist
from rethinking import LM, coef
```

In [2]:

```
print("All models are wrong, but some are useful.")
```

In [3]:

```
x = torch.arange(1., 3)
x = x * 10
x = x.log()
x = x.sum()
x = x.exp()
x
```

Out[3]:

In [4]:

```
print(torch.tensor(0.01).pow(200).log())
print(200 * torch.tensor(0.01).log())
```

In [5]:

```
# Load the data:
# car braking distances in feet paired with speeds in km/h
# see cars.info() for details
cars = pd.read_csv("../data/cars.csv")
# fit a linear regression of distance on speed
m = LM("dist ~ speed", data=cars).run()
# estimated coefficients from the model
print(coef(m))
# plot residuals against speed
y = coef(m)["Intercept"].item() + coef(m)["speed"].item() * cars["speed"]
resid = cars["dist"] - y
ax = sns.scatterplot(cars["speed"], resid)
ax.set(xlabel="speed", ylabel="residual");
```

```
pip install jupyter pandas pyro-ppl seaborn torch
```