Talip7/scikit-learn-issues-multilabel huggingface dataset:
Unexpected <class 'AttributeError'>. 'LinearRegression' object has no attribute 'positive

My team changed to scikit-learn v1.6.1 this week. We had v1.5.1 before. Our code crashes in this exact line with the error "Unexpected <class 'AttributeError'>. 'LinearRegression' object has no attribute 'positive'".

We cannot deploy in production because of this. I am desperate enough to come here to ask for help. I do not understand why it would complain that the attribute does not exist given that we were using v1.5.1 before and the attribute has existed for 4 years now. My only guess is if we are loading a very old pickled model that does not have the attribute, so it crashes here. Unfortunately I cannot share any pieces of code as it is proprietary.

_Originally posted by @ItsIronOxide in https://github.com/scikit-learn/scikit-learn/pull/30187#discussion_r1937427235_

COMMENT:
Hi @ItsIronOxide,

thanks for opening this issue. It really helps though, if you can provide a minimal reproducible including input data. That doesn't need to contain anything proprietary, but rather be a scheme of your way to use scikit-learn models. The only thing that counts is that we see what you did and can re-create the problem.Thank you.

Labels: Needs Reproducible Code
Unexpected <class 'AttributeError'>. 'LinearRegression' object has no attribute 'positive

My team changed to scikit-learn v1.6.1 this week. We had v1.5.1 before. Our code crashes in this exact line with the error "Unexpected <class 'AttributeError'>. 'LinearRegression' object has no attribute 'positive'".

We cannot deploy in production because of this. I am desperate enough to come here to ask for help. I do not understand why it would complain that the attribute does not exist given that we were using v1.5.1 before and the attribute has existed for 4 years now. My only guess is if we are loading a very old pickled model that does not have the attribute, so it crashes here. Unfortunately I cannot share any pieces of code as it is proprietary.

_Originally posted by @ItsIronOxide in https://github.com/scikit-learn/scikit-learn/pull/30187#discussion_r1937427235_

COMMENT:
In addition to what Stefanie said, you mention unpickling estimators from older scikit-learn versions. https://scikit-learn.org/dev/model_persistence.html#replicating-the-training-environment-in-production could be helpful for you - basically: it might work, or maybe not. You should get a specific `InconsistentVersion` warning to tell you.

Without a code snippet showing what you are trying to do and the resulting traceback it is unfortunately nearly impossible to give concrete advice.

Labels: Needs Reproducible Code
Unexpected <class 'AttributeError'>. 'LinearRegression' object has no attribute 'positive

My team changed to scikit-learn v1.6.1 this week. We had v1.5.1 before. Our code crashes in this exact line with the error "Unexpected <class 'AttributeError'>. 'LinearRegression' object has no attribute 'positive'".

We cannot deploy in production because of this. I am desperate enough to come here to ask for help. I do not understand why it would complain that the attribute does not exist given that we were using v1.5.1 before and the attribute has existed for 4 years now. My only guess is if we are loading a very old pickled model that does not have the attribute, so it crashes here. Unfortunately I cannot share any pieces of code as it is proprietary.

_Originally posted by @ItsIronOxide in https://github.com/scikit-learn/scikit-learn/pull/30187#discussion_r1937427235_

COMMENT:
Closing due to lack of activity from the OP. Happy to reopen if you get to work on this further.

Labels: Needs Reproducible Code
Version 1.0.2 requires numpy<2

### Describe the bug

Installing scikit-learn version 1.0.2 leads to the following error:
```bash
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

This seems to indicate a mismatch between this version of scikit-learn and numpy versions greater than 2.0 (Specifically 2.2.2 was being installed, following the only restriction of `numpy>=1.14.6`).

This can be solved by indicating to use a numpy version older than 2.0 by modifying step 1 to:
```bash
pip install "scikit-learn==1.0.2" "numpy<2"
```

## Additional references

https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

https://stackoverflow.com/questions/78650222/valueerror-numpy-dtype-size-changed-may-indicate-binary-incompatibility-expec




### Steps/Code to Reproduce

1. Install scikit-learn through pip
```bash
pip install "scikit-learn==1.0.2"
```
2. Use scikit-learn
````python
% path/to/script.py
...
from sklearn.datasets import load_iris
...
````



### Expected Results

No errors thrown

### Actual Results

Error is thrown:

```bash
path/to/script.py:2: in <module>
    from sklearn.datasets import load_iris
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/__init__.py:82: in <module>
    from .base import clone
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/base.py:17: in <module>
    from .utils import _IS_32BIT
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/utils/__init__.py: in <module>
    from .murmurhash import murmurhash3_32
sklearn/utils/murmurhash.pyx:1: in init sklearn.utils.murmurhash
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
OS: Ubuntu 24.10 (latest)
Python version 3.10
Scikit-learn version: 1.0.2
pip version: 24.3.1
setuptools version: 65.5.0
```

COMMENT:
Thanks for the issue, indeed it is less than great for users, but doing something about it is not trivial at all, see https://github.com/scikit-learn/scikit-learn/issues/29630#issuecomment-2322761297 for more details why.

So for now, the consensus is that people will hopefully find issues like yours with enough details to fix the problem themselves.

Out of curiosity, do you have a reason to install scikit-learn=1.0.2 which has been released a while ago (December 2021)? One known reason is that you are using python 3.7.

Labels: Bug, Needs Triage
Version 1.0.2 requires numpy<2

### Describe the bug

Installing scikit-learn version 1.0.2 leads to the following error:
```bash
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

This seems to indicate a mismatch between this version of scikit-learn and numpy versions greater than 2.0 (Specifically 2.2.2 was being installed, following the only restriction of `numpy>=1.14.6`).

This can be solved by indicating to use a numpy version older than 2.0 by modifying step 1 to:
```bash
pip install "scikit-learn==1.0.2" "numpy<2"
```

## Additional references

https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

https://stackoverflow.com/questions/78650222/valueerror-numpy-dtype-size-changed-may-indicate-binary-incompatibility-expec




### Steps/Code to Reproduce

1. Install scikit-learn through pip
```bash
pip install "scikit-learn==1.0.2"
```
2. Use scikit-learn
````python
% path/to/script.py
...
from sklearn.datasets import load_iris
...
````



### Expected Results

No errors thrown

### Actual Results

Error is thrown:

```bash
path/to/script.py:2: in <module>
    from sklearn.datasets import load_iris
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/__init__.py:82: in <module>
    from .base import clone
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/base.py:17: in <module>
    from .utils import _IS_32BIT
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/utils/__init__.py: in <module>
    from .murmurhash import murmurhash3_32
sklearn/utils/murmurhash.pyx:1: in init sklearn.utils.murmurhash
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
OS: Ubuntu 24.10 (latest)
Python version 3.10
Scikit-learn version: 1.0.2
pip version: 24.3.1
setuptools version: 65.5.0
```

COMMENT:
I am going to close this issue because it is unlikely that we will do anything about it, thanks for your understanding 🙏!

Labels: Bug, Needs Triage
Version 1.0.2 requires numpy<2

### Describe the bug

Installing scikit-learn version 1.0.2 leads to the following error:
```bash
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

This seems to indicate a mismatch between this version of scikit-learn and numpy versions greater than 2.0 (Specifically 2.2.2 was being installed, following the only restriction of `numpy>=1.14.6`).

This can be solved by indicating to use a numpy version older than 2.0 by modifying step 1 to:
```bash
pip install "scikit-learn==1.0.2" "numpy<2"
```

## Additional references

https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

https://stackoverflow.com/questions/78650222/valueerror-numpy-dtype-size-changed-may-indicate-binary-incompatibility-expec




### Steps/Code to Reproduce

1. Install scikit-learn through pip
```bash
pip install "scikit-learn==1.0.2"
```
2. Use scikit-learn
````python
% path/to/script.py
...
from sklearn.datasets import load_iris
...
````



### Expected Results

No errors thrown

### Actual Results

Error is thrown:

```bash
path/to/script.py:2: in <module>
    from sklearn.datasets import load_iris
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/__init__.py:82: in <module>
    from .base import clone
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/base.py:17: in <module>
    from .utils import _IS_32BIT
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/utils/__init__.py: in <module>
    from .murmurhash import murmurhash3_32
sklearn/utils/murmurhash.pyx:1: in init sklearn.utils.murmurhash
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
OS: Ubuntu 24.10 (latest)
Python version 3.10
Scikit-learn version: 1.0.2
pip version: 24.3.1
setuptools version: 65.5.0
```

COMMENT:
I would also be genuinely interested to know the reasons to install such an old version of scikit-learn. Are there too many breaking changes in newer versions that would require significant changes in your code or in some dependencies of your deployment?

Labels: Bug, Needs Triage
Version 1.0.2 requires numpy<2

### Describe the bug

Installing scikit-learn version 1.0.2 leads to the following error:
```bash
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

This seems to indicate a mismatch between this version of scikit-learn and numpy versions greater than 2.0 (Specifically 2.2.2 was being installed, following the only restriction of `numpy>=1.14.6`).

This can be solved by indicating to use a numpy version older than 2.0 by modifying step 1 to:
```bash
pip install "scikit-learn==1.0.2" "numpy<2"
```

## Additional references

https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

https://stackoverflow.com/questions/78650222/valueerror-numpy-dtype-size-changed-may-indicate-binary-incompatibility-expec




### Steps/Code to Reproduce

1. Install scikit-learn through pip
```bash
pip install "scikit-learn==1.0.2"
```
2. Use scikit-learn
````python
% path/to/script.py
...
from sklearn.datasets import load_iris
...
````



### Expected Results

No errors thrown

### Actual Results

Error is thrown:

```bash
path/to/script.py:2: in <module>
    from sklearn.datasets import load_iris
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/__init__.py:82: in <module>
    from .base import clone
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/base.py:17: in <module>
    from .utils import _IS_32BIT
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/utils/__init__.py: in <module>
    from .murmurhash import murmurhash3_32
sklearn/utils/murmurhash.pyx:1: in init sklearn.utils.murmurhash
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
OS: Ubuntu 24.10 (latest)
Python version 3.10
Scikit-learn version: 1.0.2
pip version: 24.3.1
setuptools version: 65.5.0
```

COMMENT:
@lesteve Totally understandable, I just wanted to report it here, as it took me some time to figure it out.

@ogrisel GCP prebuilt training containers for scikit learn have this as the most recent version (see [here](https://cloud.google.com/vertex-ai/docs/training/pre-built-containers?hl=es-419#scikit-learn)), so if you want to test locally before training on the cloud you need to use the same version.

Labels: Bug, Needs Triage
Version 1.0.2 requires numpy<2

### Describe the bug

Installing scikit-learn version 1.0.2 leads to the following error:
```bash
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

This seems to indicate a mismatch between this version of scikit-learn and numpy versions greater than 2.0 (Specifically 2.2.2 was being installed, following the only restriction of `numpy>=1.14.6`).

This can be solved by indicating to use a numpy version older than 2.0 by modifying step 1 to:
```bash
pip install "scikit-learn==1.0.2" "numpy<2"
```

## Additional references

https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

https://stackoverflow.com/questions/78650222/valueerror-numpy-dtype-size-changed-may-indicate-binary-incompatibility-expec




### Steps/Code to Reproduce

1. Install scikit-learn through pip
```bash
pip install "scikit-learn==1.0.2"
```
2. Use scikit-learn
````python
% path/to/script.py
...
from sklearn.datasets import load_iris
...
````



### Expected Results

No errors thrown

### Actual Results

Error is thrown:

```bash
path/to/script.py:2: in <module>
    from sklearn.datasets import load_iris
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/__init__.py:82: in <module>
    from .base import clone
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/base.py:17: in <module>
    from .utils import _IS_32BIT
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/utils/__init__.py: in <module>
    from .murmurhash import murmurhash3_32
sklearn/utils/murmurhash.pyx:1: in init sklearn.utils.murmurhash
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
OS: Ubuntu 24.10 (latest)
Python version 3.10
Scikit-learn version: 1.0.2
pip version: 24.3.1
setuptools version: 65.5.0
```

COMMENT:
This is very interesting feedback! That might explain (part of) a mystery about our pypi download statistics.

Given this information, maybe we might want to make the effort to issue `.post0` release to upper bound the version of numpy for older scikit-learn versions.

Labels: Bug, Needs Triage
Version 1.0.2 requires numpy<2

### Describe the bug

Installing scikit-learn version 1.0.2 leads to the following error:
```bash
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

This seems to indicate a mismatch between this version of scikit-learn and numpy versions greater than 2.0 (Specifically 2.2.2 was being installed, following the only restriction of `numpy>=1.14.6`).

This can be solved by indicating to use a numpy version older than 2.0 by modifying step 1 to:
```bash
pip install "scikit-learn==1.0.2" "numpy<2"
```

## Additional references

https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

https://stackoverflow.com/questions/78650222/valueerror-numpy-dtype-size-changed-may-indicate-binary-incompatibility-expec




### Steps/Code to Reproduce

1. Install scikit-learn through pip
```bash
pip install "scikit-learn==1.0.2"
```
2. Use scikit-learn
````python
% path/to/script.py
...
from sklearn.datasets import load_iris
...
````



### Expected Results

No errors thrown

### Actual Results

Error is thrown:

```bash
path/to/script.py:2: in <module>
    from sklearn.datasets import load_iris
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/__init__.py:82: in <module>
    from .base import clone
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/base.py:17: in <module>
    from .utils import _IS_32BIT
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/utils/__init__.py: in <module>
    from .murmurhash import murmurhash3_32
sklearn/utils/murmurhash.pyx:1: in init sklearn.utils.murmurhash
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
OS: Ubuntu 24.10 (latest)
Python version 3.10
Scikit-learn version: 1.0.2
pip version: 24.3.1
setuptools version: 65.5.0
```

COMMENT:
@grudloff thanks for the feed-back indeed and detailed issue, that may help more people fixing their own issue 🙏.

@ogrisel I don't think this explains completely why 1.0.2 is our most popular release because last time I looked 1.0.2 downloads were mostly coming from Python 3.7 see plot below (and GCP prebuilt container with 1.0.2 is Python 3.10 if I understood the link mentioned above), but maybe that's still something to think about.

![Image](https://github.com/user-attachments/assets/01313cd0-1c3c-4768-bc2f-292c7d772fce)

Labels: Bug, Needs Triage
Version 1.0.2 requires numpy<2

### Describe the bug

Installing scikit-learn version 1.0.2 leads to the following error:
```bash
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

This seems to indicate a mismatch between this version of scikit-learn and numpy versions greater than 2.0 (Specifically 2.2.2 was being installed, following the only restriction of `numpy>=1.14.6`).

This can be solved by indicating to use a numpy version older than 2.0 by modifying step 1 to:
```bash
pip install "scikit-learn==1.0.2" "numpy<2"
```

## Additional references

https://stackoverflow.com/questions/66060487/valueerror-numpy-ndarray-size-changed-may-indicate-binary-incompatibility-exp

https://stackoverflow.com/questions/78650222/valueerror-numpy-dtype-size-changed-may-indicate-binary-incompatibility-expec




### Steps/Code to Reproduce

1. Install scikit-learn through pip
```bash
pip install "scikit-learn==1.0.2"
```
2. Use scikit-learn
````python
% path/to/script.py
...
from sklearn.datasets import load_iris
...
````



### Expected Results

No errors thrown

### Actual Results

Error is thrown:

```bash
path/to/script.py:2: in <module>
    from sklearn.datasets import load_iris
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/__init__.py:82: in <module>
    from .base import clone
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/base.py:17: in <module>
    from .utils import _IS_32BIT
/opt/hostedtoolcache/Python/3.10.16/x64/lib/python3.10/site-packages/sklearn/utils/__init__.py: in <module>
    from .murmurhash import murmurhash3_32
sklearn/utils/murmurhash.pyx:1: in init sklearn.utils.murmurhash
    ???
E   ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject
```

### Versions

```shell
OS: Ubuntu 24.10 (latest)
Python version 3.10
Scikit-learn version: 1.0.2
pip version: 24.3.1
setuptools version: 65.5.0
```

COMMENT:
Glad to help!

Labels: Bug, Needs Triage
Error in `d2_log_loss_score` multiclass when one of the classes is missing in `y_true`.

### Describe the bug

Hello, I encountered an error with the `d2_log_loss_score` in the multiclass setting (i.e. when `y_pred` has shape (n, k) with k >= 3) when one of the classes is missing from the `y_true` labels, even when giving the labels through the `labels` argument. The error disappear when all the classes are present in `y_true`.

### Steps/Code to Reproduce

```python
from sklearn.metrics import d2_log_loss_score

y_true = [0, 1, 1]
y_pred = [[1, 0, 0], [1, 0, 0], [1, 0, 0]]
labels = [0, 1, 2]

d2_log_loss_score(y_true, y_pred, labels=labels)
```

### Expected Results

No error is thrown.

### Actual Results

```
Traceback (most recent call last):
  File "minimal.py", line 7, in <module>
    d2_log_loss_score(y_true, y_pred, labels=labels)
  File ".../python3.12/site-packages/sklearn/utils/_param_validation.py", line 216, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.12/site-packages/sklearn/metrics/_classification.py", line 3407, in d2_log_loss_score
    denominator = log_loss(
                  ^^^^^^^^^
  File ".../python3.12/site-packages/sklearn/utils/_param_validation.py", line 189, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.12/site-packages/sklearn/metrics/_classification.py", line 3023, in log_loss
    raise ValueError(
ValueError: The number of classes in labels is different from that in y_pred. Classes found in labels: [0 1 2]
```

### Versions

```shell
System:
    python: 3.12.8 | packaged by conda-forge | (main, Dec  5 2024, 14:19:53) [Clang 18.1.8 ]
executable: /Users/alexandreperez/dev/lib/miniforge3/envs/test/bin/python
   machine: macOS-15.2-arm64-arm-64bit

Python dependencies:
      sklearn: 1.6.1
          pip: 24.3.1
   setuptools: 75.8.0
        numpy: 2.2.2
        scipy: 1.15.1
       Cython: None
       pandas: None
   matplotlib: None
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 14
         prefix: libomp
       filepath: .../miniforge3/envs/test/lib/python3.12/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
```

COMMENT:
Indeed, I can reproduce, looks like an oversight, but more investigation is needed.

Labels: Bug, Needs Investigation