Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: interpolators, smoothers and splines #2361

@josef-pkt

Description

@josef-pkt

The type of models that have only a few (for memory consumption) basis functions, can be estimated and used by our regular models, or by looking at the (nobs, nobs) "kernel" matrix.

Examples:
Kernel Ridge Regression in sandbox
scikit smooth
http://mail.scipy.org/pipermail/scipy-dev/2015-April/020617.html with link to code on scipy-central
(has a nice class structure that could be used in a similar way for subclassing with choice of basis function)

creating a projection matrix based on splines.
Use case: Matthews on scipy-dev: having a single 1d exog x, but many endog y.

Using patsy's bsplines doesn't handle boundaries properly. problems with extrapolation. That will need more work.
(Also using the bspline in a formula with OLS works fine for fitting, but I had an exception in the predict. traceback will follow in next comment.)

>>> spb2 = patsy.dmatrix("bs(x, df=10, degree=3, include_intercept=True) - 1", {'x': np.arange(0,10, 0.25)})
>>> project = spb2.dot(np.linalg.pinv(spb2[::4]))
>>> y = np.sin(np.linspace(-np.pi, np.pi, 10))
>>> y2 = np.sin(2*np.linspace(-np.pi, np.pi, 10))
>>> y3 = np.sin(1.5*np.linspace(-np.pi, np.pi, 10))
>>> pred = project.dot(np.column_stack((y,y2,y3)))
>>> plt.plot(np.arange(0,10, 0.25)[::4], np.column_stack((y,y2,y3)), "o")
[<matplotlib.lines.Line2D object at 0x000000000D032D30>, <matplotlib.lines.Line2D object at 0x000000000D032B38>, <matplotlib.lines.Line2D object at 0x000000000D032438>]
>>> plt.plot(np.arange(0,10, 0.25), pred, "+-")
[<matplotlib.lines.Line2D object at 0x000000000D080D68>, <matplotlib.lines.Line2D object at 0x000000000D080518>, <matplotlib.lines.Line2D object at 0x000000000D083080>]
>>> plt.ylim(-1.2, 1.2)
(-1.2, 1.2)
>>> plt.show()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions