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]: TypeError: _check_feature_names_in() got an unexpected keyword argument 'generate_names' #392

Closed
noneaddress opened this issue Jul 30, 2023 · 4 comments · Fixed by #393
Assignees
Labels
bug Something isn't working priority: high

Comments

@noneaddress
Copy link

noneaddress commented Jul 30, 2023

What happened?

I use anaconda to manage my Python pkgs. But conda install -c conda-forge pysr failed to install pysr because it spent lots of time on solving environment. Thus I installed Julia and pysr with pip in conda prompt.
However, when running demos in Quickstart section of README.md, an error occurred.
TypeError: _check_feature_names_in() got an unexpected keyword argument 'generate_names'

Version

0.15.0

Operating System

Windows

Package Manager

pip

Interface

IPython Terminal

Relevant log output

raceback (most recent call last):
  File "E:/PCprofessional/PyCharm 2022.2.3/plugins/python/helpers/pydev/pydevd.py", line 1496, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "E:\PCprofessional\PyCharm 2022.2.3\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "F:\MasterDegreeCode\EnDeCoder\symboltest.py", line 17, in <module>
    model.fit(X, y)
  File "E:\CondaFolder\envs\Symbol\lib\site-packages\pysr\sr.py", line 1910, in fit
    X, y, Xresampled, weights, variable_names, X_units, y_units
  File "E:\CondaFolder\envs\Symbol\lib\site-packages\pysr\sr.py", line 1442, in _validate_and_set_fit_params
    self, variable_names, generate_names=False
TypeError: _check_feature_names_in() got an unexpected keyword argument 'generate_names'

Extra Info

Here is the script.

import numpy as np
import pysr
from pysr import PySRRegressor
#%%
X = 2 * np.random.randn(100, 5)
y = 2.5382 * np.cos(X[:, 3]) + X[:, 0] ** 2 - 0.5

from pysr import PySRRegressor

model = PySRRegressor(
    niterations=40,  # < Increase me for better results
    binary_operators=["+", "*"],
    unary_operators=[
        "cos",
        "exp",
        "sin",
        "inv(x) = 1/x",
        # ^ Custom operator (julia syntax)
    ],
    extra_sympy_mappings={"inv": lambda x: 1 / x},
    # ^ Define operator for SymPy as well
    loss="loss(prediction, target) = (prediction - target)^2",
    # ^ Custom loss function (julia syntax)
)

model.fit(X, y)

print(model)

I created a new anaconda env and installed pysr in it. Both the envs throw the same error. I have run pysr.install() in these two envs before running the script above.
I used Debug in Pycharm and found that function _check_feature_names_in defined in \Lib\site-packages\sklearn\utils\validation.py only has input_features=None.
When generate_names=False in _check_feature_names_in(line 1441 in \Lib\site-packages\pysr\sr.py) is commented, the script runs normally. And I got the following results.

complexity loss score equation sympy_format lambda_format
0 1 37.918518 0.0 4.501644 4.50164400000000 PySRFunction(X=>4.50164400000000)
1 3 2.887665 1.287495688636072 (x0 * x0) x0**2 PySRFunction(X=>x0**2)
2 5 2.8626113 0.0043569834259625665 (x0 * (x0 * 0.97915745)) 0.97915745*x0**2 PySRFunction(X=>0.97915745*x0**2)
3 6 1.1332736 0.9266238145378896 ((x0 * x0) + cos(x3)) x0**2 + cos(x3) PySRFunction(X=>x0**2 + cos(x3))
4 8 0.23931366 0.777545319110213 ((x0 * x0) + (cos(x3) * 2.3865998)) x0**2 + 2.3865998*cos(x3) PySRFunction(X=>x0**2 + 2.3865998*cos(x3))
5 9 0.23632519 0.012566296155662461 ((x0 * x0) + (sin(cos(x3)) * 2.7109928)) x0**2 + 2.7109928*sin(cos(x3)) PySRFunction(X=>x0**2 + 2.7109928*sin(cos(x3)))
6 10 2.2233993e-13 27.692022469244964 ((x0 * x0) + ((cos(x3) + -0.19699001) * 2.5382)) x0**2 + 2.5382*cos(x3) - 0.500000043382 PySRFunction(X=>x0**2 + 2.5382*cos(x3) - 0.500000043382)
7 12 1.9617641e-13 0.0625965607621989 ((x0 * x0) + ((cos(x3) * (2.0843496 * 1.2177418)) + -0.50000006)) x0**2 + 2.53819963373328*cos(x3) - 0.50000006 PySRFunction(X=>x0**2 + 2.53819963373328*cos(x3) - 0.50000006)

I wonder whether there are something wrong with my pkgs or project structures. Looking forward to your reply.


Besides, when I add print(model.latex_table(precision=3, include_score=True)) at the end of the above script, an error occurred.
TypeError: latex_table() got an unexpected keyword argument 'include_score'


I just started learning programming, and my English is not very proficient. Please forgive me if I have offended or made low-level mistakes.

Best,
Ker

@noneaddress noneaddress added the bug Something isn't working label Jul 30, 2023
@MilesCranmer
Copy link
Owner

Thanks very much for the bug report. This looks like the scikit-learn version being installed is out-of-date, so I either need to implement a version requirement, or need to add a fallback method.

@MilesCranmer
Copy link
Owner

Let me know if you still run into any issues

@noneaddress
Copy link
Author

noneaddress commented Jul 31, 2023

Let me know if you still run into any issues

Hi Miles Cranmer. pysr runs normally after upgrading to 0.15.1 with pip. However, I encountered these warnings .

`UserWarning: `torch` was loaded before the Julia instance started. This may cause a segfault when running `PySRRegressor.fit`. To avoid this, please run `pysr.julia_helpers.init_julia()` *before* importing `torch`. For updates, see https://github.com/pytorch/pytorch/issues/78829
  "`torch` was loaded before the Julia instance started. "`

`E:\CondaFolder\envs\env_one\lib\site-packages\pysr\julia_helpers.py:209: UserWarning: Your system's Python library is static (e.g., conda), so precompilation will be turned off. For a dynamic library, try using `pyenv` and installing with `--enable-shared`: https://github.com/pyenv/pyenv/blob/master/plugins/python-build/README.md#building-with---enable-shared.
  "Your system's Python library is static (e.g., conda), so precompilation will be turned off. For a dynamic library, try using `pyenv` and installing with `--enable-shared`: https://github.com/pyenv/pyenv/blob/master/plugins/python-build/README.md#building-with---enable-shared."`

It provides detailed info, and I am confident to handle these. Thank you for developing pysr and fixing the bug so quickly~

@MilesCranmer
Copy link
Owner

Cool. Yes, those warnings are unrelated – feel free to address if you desire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: high
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants