简体   繁体   中英

How to you find the basis expansion matrix in python

I'm doing nonparametric regression, and need a function to expand the design matrix X into the basis matrix. Is there a package that can do this?

For example, if X is 200*10 (200 obs and 10 features), using a B-spline basis expansion with 5 bases will yield a 200*50 basis matrix.

I tried scipy.interpolate.BSpline , but it seems it does not return the basis matrix.

The pasty library in python is useful.

from pasty import dmatrix

transformed_x = dmatrix(
                    "bs(x, df=df, degree=degree, include_intercept=False)",
                    {"train": x}, return_type='matrix')

This will return the basis expansion for a vector x. If you have a data matrix, do this for each column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM