Skip to content

[BUG] Too many values to unpack with sklearn 1.8 #671

@loiseaujc

Description

@loiseaujc

Hej guys,

It seems like sklearn has changed something between 1.7 and 1.8 (eventhough I couldn't find it in the changelog) about how _preprocess_data behaves. The following code now raises a Too many values to unpack while it worked flawlessly with sklearn 1.7.2

Reproducing code example:

import numpy as np
import scipy as sp
import pysindy as ps
import sklearn as sk

from scipy.integrate import solve_ivp

def lorenz(t, u, p):
    #> Unpack variables.
    x, y, z = u
    #> Unpack parameters.
    σ, ρ, β = p
    #> Equations.
    dx = σ*(y - x)
    dy = x*(ρ-z) - y
    dz = x*y - β*z
    return dx, dy, dz

#> Parameters for the simulation.
p = σ, ρ, β = 10.0, 28.0, 8.0/3.0
u0 = np.array([1.0, 1.0, 1.0])
t = np.linspace(0, 100, 10000) ; Δt = t[1] - t[0]
tspan = (t.min(), t.max())

#> Run the simulation.
solution = solve_ivp(
    lambda t, u : lorenz(t, u, p),
    tspan,
    u0,
    t_eval = t
)

#> Divise les données entre jeu de test et jeu d'entraînement.
n = len(solution.y[0]) # Nombre de points de données.
x_train = solution.y[:, :3*n//4].T
x_test = solution.y[:, 3*n//4:].T
t_test = t[3*n//4:]

#> Création de l'estimateur SINDy.
model = ps.SINDy(
    optimizer = ps.STLSQ(), # Choix de l'optimisateur.
    feature_library = ps.PolynomialLibrary(degree=5) # Choix de la base de fonctions.
)

#> Entraînement du modèle.
model.fit(
    x_train, # Jeu d'entraînement.
    t = Δt, # Pas de temps.,
    feature_names=["x", "y", "z"]
)

Error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[7], line 14
      8 model = ps.SINDy(
      9     optimizer = ps.STLSQ(), # Choix de l'optimisateur.
     10     feature_library = ps.PolynomialLibrary(degree=5) # Choix de la base de fonctions.
     11 )
     13 #> Entraînement du modèle.
---> 14 model.fit(
     15     x_train, # Jeu d'entraînement.
     16     t = Δt, # Pas de temps.,
     17     feature_names=["x", "y", "z"]
     18 )

File [~/miniconda3/envs/pysindy/lib/python3.14/site-packages/pysindy/pysindy.py:382](http://localhost:46683/home/loiseau/miniconda3/envs/pysindy/lib/python3.14/site-packages/pysindy/pysindy.py#line=381), in SINDy.fit(self, x, t, x_dot, u, feature_names)
    380 x_dot = concat_sample_axis(x_dot)
    381 self.model = Pipeline(steps)
--> 382 self.model.fit(x, x_dot)
    383 self._fit_shape()
    385 return self

File [~/miniconda3/envs/pysindy/lib/python3.14/site-packages/sklearn/base.py:1336](http://localhost:46683/home/loiseau/miniconda3/envs/pysindy/lib/python3.14/site-packages/sklearn/base.py#line=1335), in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs)
   1329     estimator._validate_params()
   1331 with config_context(
   1332     skip_parameter_validation=(
   1333         prefer_skip_nested_validation or global_skip_validation
   1334     )
   1335 ):
-> 1336     return fit_method(estimator, *args, **kwargs)

File [~/miniconda3/envs/pysindy/lib/python3.14/site-packages/sklearn/pipeline.py:621](http://localhost:46683/home/loiseau/miniconda3/envs/pysindy/lib/python3.14/site-packages/sklearn/pipeline.py#line=620), in Pipeline.fit(self, X, y, **params)
    615     if self._final_estimator != "passthrough":
    616         last_step_params = self._get_metadata_for_step(
    617             step_idx=len(self) - 1,
    618             step_params=routed_params[self.steps[-1][0]],
    619             all_params=params,
    620         )
--> 621         self._final_estimator.fit(Xt, y, **last_step_params["fit"])
    623 return self

File [~/miniconda3/envs/pysindy/lib/python3.14/site-packages/pysindy/optimizers/base.py:176](http://localhost:46683/home/loiseau/miniconda3/envs/pysindy/lib/python3.14/site-packages/pysindy/optimizers/base.py#line=175), in BaseOptimizer.fit(self, x_, y, sample_weight, **reduce_kws)
    173 x_, y = drop_nan_samples(x_, y)
    174 x_, y = check_X_y(x_, y, accept_sparse=[], y_numeric=True, multi_output=True)
--> 176 x, y, X_offset, y_offset, X_scale = _preprocess_data(
    177     x_,
    178     y,
    179     fit_intercept=False,
    180     copy=self.copy_X,
    181     sample_weight=sample_weight,
    182 )
    184 if sample_weight is not None:
    185     x, y = _rescale_data(x, y, sample_weight)

ValueError: too many values to unpack (expected 5, got 6)

PySINDy/Python version information:

  • psyndy 2.0.0
  • numpy 2.4.0
  • scikit-learn 1.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions