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

[BUG] Cannot run the example code #179

Closed
tyy4n9 opened this issue May 14, 2022 · 5 comments
Closed

[BUG] Cannot run the example code #179

tyy4n9 opened this issue May 14, 2022 · 5 comments

Comments

@tyy4n9
Copy link

tyy4n9 commented May 14, 2022

I just installed pysindy on my computer through "pip install pysindy".
However, I failed to run the example codes. It always shows 'STLSQ' object has no attribute '_preprocess_data'.
I installed python through Anaconda, and I used spyder to run the code.

Reproducing code example:

import numpy as np
import pysindy as ps

t = np.linspace(0, 1, 100)
x = 3 * np.exp(-2 * t)
y = 0.5 * np.exp(t)
X = np.stack((x, y), axis=-1)  # First column is x, second is y

model = ps.SINDy(feature_names=["x", "y"])
model.fit(X, t=t)

Error message:

Traceback (most recent call last):

File "C:\Users\AppData\Local\Temp\ipykernel_11640\1278902783.py", line 16, in <cell line: 16>
model.fit(X, t=t)

File "d:\pysindy.py", line 563, in fit
self.model.fit(x, x_dot)

File "E:\anaconda3\envs\pysindy\lib\site-packages\sklearn\pipeline.py", line 382, in fit
self._final_estimator.fit(Xt, y, **fit_params_last_step)

File "d:\pysindy\optimizers\sindy_optimizer.py", line 58, in fit
self.optimizer.fit(x, y)

File "d:\pysindy\optimizers\base.py", line 134, in fit
x, y, X_offset, y_offset, X_scale = self._preprocess_data(

AttributeError: 'STLSQ' object has no attribute '_preprocess_data'

@akaptano
Copy link
Collaborator

What are your pysindy and sklearn versions?

@jcallaham
Copy link
Collaborator

jcallaham commented May 17, 2022

I get the same error with pysindy 1.7 and sklearn 1.1.0. Actually about half of the tests seem to be failing. Looks like this might be the culprit:

scikit-learn/scikit-learn#22762

They changed _preprocess_data from a static method to just a regular function. An easy fix would be to import the function from sklearn.linear_models._base. I don't really know if that's good practice, since the function doesn't seem to be intended for public use, but I'm just going to do that for now to get things working again at least.

Also, since _preprocess_data was already a function in that module I think this fix should be backwards compatible.

@tyy4n9
Copy link
Author

tyy4n9 commented May 17, 2022

Thanks for the reply. Yes, I think the problem comes from the version of the scikit-learn. If I created a new env and
installed pysindy on this environment, this will not work (sklearn: 1.0.0). However, if I cloned
the base environment (Anaconda default environment, sklearn: 0.24.1) and installed pysindy on it, this will work.

@tyy4n9 tyy4n9 closed this as completed May 17, 2022
@akaptano
Copy link
Collaborator

akaptano commented May 17, 2022

@briandesilva Any thoughts on the fix? This is a bit how sklearn version 1.0 broke the column normalization functionality in the sklearn regression.

Thanks Jared for pointing out the issue

@panandreou
Copy link

I have the latest version of python and the latest version of pysindy. The error is still occurring. I don't understand what is meant by the newest version of the main branch. pip will not let me install an older version of sklearn.

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

4 participants