tpot icon indicating copy to clipboard operation
tpot copied to clipboard

Import issue with tpot 0.12.0 and sklearn 1.0.2

Open DManowitz opened this issue 2 years ago • 5 comments

[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 avatar Aug 07 '23 02:08 DManowitz

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.

windowshopr avatar Aug 12 '23 20:08 windowshopr

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

DManowitz avatar Aug 13 '23 01:08 DManowitz

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.

windowshopr avatar Aug 14 '23 01:08 windowshopr

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())

GianlucaDF avatar Jan 07 '24 12:01 GianlucaDF