dswah / pyGAM

[HELP REQUESTED] Generalized Additive Models in Python
https://pygam.readthedocs.io
Apache License 2.0
876 stars 160 forks source link

Is there a way to get knot locations from a fitted model? #265

Open jjlevinemusic opened 4 years ago

jjlevinemusic commented 4 years ago

I would like to run plain regressions on the data once pygam has found the right knots. Is there any way to get this out of fitted model?

shyamcody commented 4 years ago

In gam model, uniform knots are fitted. So basically to generate all the knots, you need the initial and final knots. To get those two knots, you need to use the gen_edge_knots function from pygam.utils. I will provide a small code for the same below: from pygam.utils import gen_edge_knots feature_data = [i for i in range(100)] knots_array = gen_edge_knots(data = feature_data,dtype = 'numerical') This will result in knots_array having the value array([0,99]). Then you can use the number of knots and divide this portion into uniform knot points. For using the gen_edge_knots function, you must provide the data and the dtype parameter. dtype has two options only, numerical and categorical.

jjlevinemusic commented 4 years ago

Thanks for responding. To be clear, finding uniform distributed points is pretty straightforward, there is no need to run a gam to find those points. Perhaps what would be useful would be to find all the points with a significant coefficient. That could then be used as the "joints" of a simple regression

dswah commented 4 years ago

@jjlevinemusic The statistical tests in pygam are group-wise. This makes it possible to test if an entire feature is significant. However it means that we cannot say anything about individual splines.