scikit-learn-contrib / py-earth

A Python implementation of Jerome Friedman's Multivariate Adaptive Regression Splines
http://contrib.scikit-learn.org/py-earth/
BSD 3-Clause "New" or "Revised" License
457 stars 121 forks source link

knot positions and polynomial coefficients #161

Open ivanlen opened 7 years ago

ivanlen commented 7 years ago

Hi, I was checking the documentation and I couldn't how to find the knots positions and the values of the coefficients of the different polynomials of the fit. Let's say that I fit the data (x,y) and the fit has k knots and max_degree=m. How I find out the values of k values of the knots and the (m+1) coefficient of each the piecewise polynomials. Sorry for the knot question, I imagine some numerical recipes but I probably there is a really straightforward way that I can't find out.

By the way, congrats to the developers of the package, it is super useful and performs really well.

jcrudy commented 7 years ago

@ivanlen The coefficients for all terms, including the constant term, are stored in the coef_ attribute of the fitted model. Knot positions and coefficients can be found by inspecting the string produced by the summary method. Alternatively, you can inspect the attributes of the basis_ attribute of the fitted model. It's also possible to export to a sympy expression, using the pyearth.export.export_sympy function.