Skip to content

Instantly share code, notes, and snippets.

@tavin
Created May 17, 2018 17:13
Show Gist options
  • Save tavin/e952f67113db80f2951e5076d7c78b92 to your computer and use it in GitHub Desktop.
Save tavin/e952f67113db80f2951e5076d7c78b92 to your computer and use it in GitHub Desktop.
b-spline quantile regression with statsmodels
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
import statsmodels.formula.api as smf
x = np.linspace(0, 2, 100)
y = np.sqrt(x) * np.sin(2 * np.pi * x) + np.random.random_sample(100)
mod = smf.quantreg('y ~ bs(x, df=9)', dict(x=x, y=y))
res = mod.fit(q=0.5)
print(res.summary())
plt.plot(x, y, '.')
plt.plot(x, res.predict(), 'r')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment