Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

augment_spline API #300

Open
marcozanotti opened this issue Sep 19, 2024 · 1 comment
Open

augment_spline API #300

marcozanotti opened this issue Sep 19, 2024 · 1 comment

Comments

@marcozanotti
Copy link

Hi @mdancho84 ,

thanks for this amazing porting of timetk in python.
I would suggest a new API called augment_spline to add Basis Splines / Natural Splines / Cyclic Splines / etc. to the dataframe as new columns.

Here is a simple example I did using statsmodels.gam.api module

@pf.register_dataframe_method
def augment_bsplines(data, column_name = 'ds_index_num', df = 5, degree = 3):
    
    bs = BSplines(
        data[column_name], 
        df = df, 
        degree = degree, 
        include_intercept = False
    )
    bs_df = pd.DataFrame(bs.basis)
    
    col_names = []
    for i in range(1, (len(bs_df.columns) + 1)):
        col_names.append(f'bspline_{i}_degree_{degree}')
    bs_df.columns = col_names
    bs_df.index = data.index

    data_splines = pd.concat([data, bs_df], axis = 1)

    return data_splines

It is far from ideal, but it is a quick way of doing it.
Thatnks a lot.
Looking forward to have all the timetk APIs in python too.

@mdancho84
Copy link
Contributor

Will take a look during the next pytimetk dev sprint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants