Skip to content

RuntimeWarnings: divide by zero, overflow, invalid value encountered in matmul #31395

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

Closed
mlescobarm opened this issue May 19, 2025 · 2 comments
Closed
Labels
Bug Needs Triage Issue requires triage

Comments

@mlescobarm
Copy link

Describe the bug

While running feature selection, I get the following warnings:
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: divide by zero encountered in matmul
ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: overflow encountered in matmul
ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: invalid value encountered in matmul
ret = a @ b

Steps/Code to Reproduce

from sklearn.datasets import make_friedman1
from sklearn.feature_selection import RFECV
from sklearn.svm import SVR
X, y = make_friedman1(n_samples=500, n_features=100, random_state=0)
estimator = SVR(kernel="linear")
selector = RFECV(estimator, step=1, cv=5)
selector = selector.fit(X, y)
print(selector.support_)

Expected Results

[ True True False True True False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False]

Actual Results

.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: divide by zero encountered in matmul
ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: overflow encountered in matmul
ret = a @ b
.../lib/python3.12/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: invalid value encountered in matmul
ret = a @ b
...
[ True True False True True False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False False False False False False False False False
False False False False]

Versions

System:
    python: 3.12.8 (v3.12.8:2dc476bcb91, Dec  3 2024, 14:43:19) [Clang 13.0.0 (clang-1300.0.29.30)]
executable: /Users/******/PyEnvs/JAN2025/bin/python
   machine: macOS-15.5-arm64-arm-64bit

Python dependencies:
      sklearn: 1.6.1
          pip: 25.1.1
   setuptools: 75.8.0
        numpy: 2.2.5
        scipy: 1.15.0
       Cython: None
       pandas: 2.2.3
   matplotlib: 3.10.0
       joblib: 1.4.2
threadpoolctl: 3.5.0

Built with OpenMP: True

threadpoolctl info:
       user_api: openmp
   internal_api: openmp
    num_threads: 10
         prefix: libomp
       filepath: /Users/******/PyEnvs/JAN2025/lib/python3.12/site-packages/sklearn/.dylibs/libomp.dylib
        version: None
@mlescobarm mlescobarm added Bug Needs Triage Issue requires triage labels May 19, 2025
@lesteve
Copy link
Member

lesteve commented May 20, 2025

I can not reproduce the behaviour on a Linux machine.

Do you happen to have a macOS M4? If you do have a macOS M4, it could be linked numpy/numpy#28687.

I am going to close this issue, because it is likely to be an issue in numpy rather than scikit-learn. Fee free to reopen if there is a clear indication that the problem is related to scikit-learn.

@lesteve lesteve closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2025
@mlescobarm
Copy link
Author

mlescobarm commented May 20, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue requires triage
Projects
None yet
Development

No branches or pull requests

2 participants