I would like to get the best of two worlds: Scipy and pygam.
Specifically, I want to penalise the third derivative of my data using a custom pygam penalty function, and then I would like to use the result as a Scipy BSpline. The latter allows for easy calculation of the n-th derivative of the data.
Of course, gam.coef_ gives me the coefficients of my model, but what are the knots?
If get close by using gam.terms.get_coef_indices()-1, but the result should really be identical to gam.predict(x), i.e.
After a helpful comment by ev-br, we know now that we can get the knot edges by pygam.utils.get_knot_edges. Therefore, a promising piece of code would be
plt.figure()
res0=pygam.LinearGAM(terms=pygam.terms.s(0),n_splines=len(x),penalties=MyPenalty,lam=0.3,fit_intercept=False, basis='ps').fit(x,y,1/np.sqrt(w))
plt.plot(x,y,'x',zorder=10, label='data')
knot_edges=utils.gen_edge_knots(x,dtype='numerical')
knots=np.linspace(knot_edges[0],knot_edges[-1],len(res0.coef_))
plt.plot(x,res0.predict(x), label='PyGAM fit')
plt.plot(x,scipy.interpolate.BSpline(knots,res0.coef_,3)(x), label='BSpline from PyGAM parameters')
plt.legend()



According to https://github.com/dswah/pyGAM/issues/265, pyfam fits uniform knots. The location of the first and last knots can be extracted via
pygam.utils.gen_edge_knots.