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

Import issue with tpot 0.12.0 and sklearn 1.0.2 #1314

Open
DManowitz opened this issue Aug 7, 2023 · 4 comments
Open

Import issue with tpot 0.12.0 and sklearn 1.0.2 #1314

DManowitz opened this issue Aug 7, 2023 · 4 comments

Comments

@DManowitz
Copy link

DManowitz commented Aug 7, 2023

[provide general introduction to the issue and why it is relevant to this repository]

Context of the issue

tpot 0.12.0 gives error with scikit-learn v1.0.2, but loads ok with scikit-learn v1.1.3

Process to reproduce the issue

import tpot

Expected result

TPOT loads without error

Current result

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│ C:\...\lib\site-packages\tpot\__init__.py:27 in                                    │
│ <module>                                                                                         │
│                                                                                                  │
│   24 """                                                                                         │
│   25                                                                                             │
│   26 from ._version import __version__                                                           │
│ ❱ 27 from .tpot import TPOTClassifier, TPOTRegressor                                             │
│   28 from .driver import main                                                                    │
│   29                                                                                             │
│                                                                                                  │
│ C:\...\lib\site-packages\tpot\tpot.py:31 in <module>   │
│                                                                                                  │
│   28                                                                                             │
│   29 import numpy as np                                                                          │
│   30                                                                                             │
│ ❱ 31 from .base import TPOTBase                                                                  │
│   32 from .config.classifier import classifier_config_dict                                       │
│   33 from .config.regressor import regressor_config_dict                                         │
│   34                                                                                             │
│                                                                                                  │
│ C:\...\lib\site-packages\tpot\base.py:83 in <module>   │
│                                                                                                  │
│     80 from .config.classifier_cuml import classifier_config_cuml                                │
│     81 from .config.regressor_cuml import regressor_config_cuml                                  │
│     82                                                                                           │
│ ❱   83 from .metrics import SCORERS                                                              │
│     84 from .gp_types import Output_Array                                                        │
│     85 from .gp_deap import (                                                                    │
│     86 │   eaMuPlusLambda,                                                                       │
│                                                                                                  │
│ C:\...\lib\site-packages\tpot\metrics.py:27 in         │
│ <module>                                                                                         │
│                                                                                                  │
│   24 """                                                                                         │
│   25                                                                                             │
│   26 import numpy as np                                                                          │
│ ❱ 27 from sklearn.metrics import get_scorer, get_scorer_names, make_scorer                       │
│   28                                                                                             │
│   29                                                                                             │
│   30 def balanced_accuracy(y_true, y_pred):                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ImportError: cannot import name 'get_scorer_names' from 'sklearn.metrics'

Possible fix

Either increase the required version of sckit-learn or fix tpot to keep current dependency.

name of issue screenshot

[if relevant, include a screenshot]

@DManowitz DManowitz changed the title sklearn issue with tpot 0.12.0 Import issue with tpot 0.12.0 and sklearn 1.0.2 Aug 7, 2023
@windowshopr
Copy link

Traceback (most recent call last):
  File ".\forward_predict.py", line 16, in <module>
    from tpot.builtins import StackingEstimator
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python38\lib\site-packages\tpot\__init__.py", line 27, in <module>
    from .tpot import TPOTClassifier, TPOTRegressor
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python38\lib\site-packages\tpot\tpot.py", line 31, in <module>
    from .base import TPOTBase
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python38\lib\site-packages\tpot\base.py", line 82, in <module>
    from .metrics import SCORERS
  File "C:\Users\chalu\AppData\Local\Programs\Python\Python38\lib\site-packages\tpot\metrics.py", line 27, in <module>
    from sklearn.metrics import make_scorer, SCORERS
ImportError: cannot import name 'SCORERS' from 'sklearn.metrics' (C:\Users\chalu\AppData\Local\Programs\Python\Python38\lib\site-packages\sklearn\metrics\__init__.py)

TPOT doesn't like latest version of scikit-learn, version 1.3.0 I believe. SCORERS isn't a part of the sklearn.metrics class anymore. Have to revert to older versions of scikit-learn.

@DManowitz
Copy link
Author

This is actually not the latest version of scikit-learn, but an older version.

@windowshopr
Copy link

Running pip install scikit-learn installs version 1.3.0 as of 2 days ago, so that seems to be the most recent stable version they're using. I see there's dev/beta versions higher than that, but I would assume that most people who install it will get version 1.3.0 by running pip install. Either way, the issue persists.

@GianlucaDF
Copy link

Add te methodget_scorer_names()in _scorer.pyinside sklearn directory and it should work if you try to import again the TPOTClassifier:

def get_scorer_names():
    """Get the names of all available scorers.

    These names can be passed to :func:`~sklearn.metrics.get_scorer` to
    retrieve the scorer object.

    Returns
    -------
    list of str
        Names of all available scorers.
    """
    return sorted(SCORERS.keys())

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

3 participants