<jupyter_start><jupyter_text>Use of `glm_utils` in a `sklearn.pipeline`.<jupyter_code>from tempfile import TemporaryDirectory
import numpy as np
from sklearn.linear_model import BayesianRidge
from sklearn.preprocessing import FunctionTransformer, PolynomialFeatures
from sklearn.pipeline import Pipeline

from glm_utils.preprocessing import time_delay_embedding

# Generate dummy data.
x = np.random.random((1000, 1))
y = np.random.random((1000,))

# Manipulations regarding X *and* y
X, y = time_delay_embedding(x, y, window_size=100)

# Transformations that only change X are included in the pipeline.
steps = [('quad_exp', PolynomialFeatures(degree=2, interaction_only=False, include_bias=True)),
         ('ridge', BayesianRidge())]

with TemporaryDirectory() as tempdir:
    model = Pipeline(steps, memory=tempdir)
    model.fit(X, y)
    y_pred, y_pred_std = model.predict(X, return_std=True)
    print(f'r2={model.score(X, y):1.2}')<jupyter_output>r2=1.0
{'fraction_non_alphanumeric': 0.11030176899063475, 'fraction_numerical': 0.019771071800208116, 'mean_word_length': 6.073529411764706, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '636888', 'license': 'MIT', 'n_tokens_mistral': 334, 'n_tokens_neox': 323, 'n_words': 80, 'path': 'demo/pipeline.ipynb', 'repo_name': 'janclemenslab/glm_utils', 'size': '961'}