patsy logo patsy: splines

1 2 3 4 5 6 7 8 9
Notes

To generate the repeating features, run;

x = np.linspace(0.0, 1.0, 100)
x_mat = ps.dmatrix("cc(x, df=5) - 1", pd.DataFrame({"x": x}))
plt.plot(x, x_mat);

The final example with splines is shown below;

df_ml = df_clean.head(1200).loc[lambda d: d['n_born'] > 2000]
y, X = ps.dmatrices("n_born ~ cc(yday, df=12)", df_ml)
mod = LinearRegression().fit(X, y)

plt.figure(figsize=(12, 3))
plt.scatter(df_ml['date'], y)
plt.plot(df_ml['date'], mod.predict(X), color='orange');