Created
May 17, 2018 17:13
-
-
Save tavin/e952f67113db80f2951e5076d7c78b92 to your computer and use it in GitHub Desktop.
b-spline quantile regression with statsmodels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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