-
-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Closed
Labels
Description
Describe the bug
I accidentally stumbled onto a ValueError when executing smacof. I hacked into _mds.py to save both the offending dissimilarities as well as the randomly generated X, then cut them down to minimal shape that still exhibits the error. This data is attached below in the MCVE.
Steps/Code to Reproduce
import numpy as np
import sklearn.manifold
dis = np.array([
[0.0, 1.732050807568877, 1.7320508075688772],
[1.732050807568877, 0.0, 6.661338147750939e-16],
[1.7320508075688772, 6.661338147750939e-16, 0.0]
])
init = np.array([
[0.08665881585055124, 0.7939114643387546],
[0.9959834154297658, 0.7555546025640025],
[0.8766008278401566, 0.4227358815811242]
])
sklearn.manifold.smacof(dis, init=init, normalized_stress="auto", metric=False, n_init=1)
Expected Results
No errors
Actual Results
Traceback (most recent call last):
File ".../rep_error.py", line 14, in <module>
sklearn.manifold.smacof(dis, init=init, normalized_stress="auto", metric=False, n_init=1)
File ".../.direnv/python-3.9.5/lib/python3.9/site-packages/sklearn/manifold/_mds.py", line 329, in smacof
pos, stress, n_iter_ = _smacof_single(
File ".../.direnv/python-3.9.5/lib/python3.9/site-packages/sklearn/manifold/_mds.py", line 128, in _smacof_single
dis = euclidean_distances(X)
File ".../.direnv/python-3.9.5/lib/python3.9/site-packages/sklearn/metrics/pairwise.py", line 310, in euclidean_distances
X, Y = check_pairwise_arrays(X, Y)
File ".../.direnv/python-3.9.5/lib/python3.9/site-packages/sklearn/metrics/pairwise.py", line 156, in check_pairwise_arrays
X = Y = check_array(
File ".../.direnv/python-3.9.5/lib/python3.9/site-packages/sklearn/utils/validation.py", line 959, in check_array
_assert_all_finite(
File ".../.direnv/python-3.9.5/lib/python3.9/site-packages/sklearn/utils/validation.py", line 124, in _assert_all_finite
_assert_all_finite_element_wise(
File ".../.direnv/python-3.9.5/lib/python3.9/site-packages/sklearn/utils/validation.py", line 173, in _assert_all_finite_element_wise
raise ValueError(msg_err)
ValueError: Input contains NaN.
Versions
System:
python: 3.9.5 (default, Nov 23 2021, 15:27:38) [GCC 9.3.0]
executable: .../.direnv/python-3.9.5/bin/python
machine: Linux-5.4.0-148-generic-x86_64-with-glibc2.31
Python dependencies:
sklearn: 1.3.0
pip: 23.2.1
setuptools: 44.0.0
numpy: 1.25.1
scipy: 1.11.1
Cython: None
pandas: None
matplotlib: None
joblib: 1.3.1
threadpoolctl: 3.2.0
Built with OpenMP: True
threadpoolctl info:
user_api: openmp
internal_api: openmp
num_threads: 32
prefix: libgomp
filepath: .../.direnv/python-3.9.5/lib/python3.9/site-packages/scikit_learn.libs/libgomp-a34b3233.so.1.0.0
version: None
user_api: blas
internal_api: openblas
num_threads: 32
prefix: libopenblas
filepath: .../.direnv/python-3.9.5/lib/python3.9/site-packages/numpy.libs/libopenblas64_p-r0-7a851222.3.23.so
version: 0.3.23
threading_layer: pthreads
architecture: Zen
user_api: blas
internal_api: openblas
num_threads: 32
prefix: libopenblas
filepath: .../.direnv/python-3.9.5/lib/python3.9/site-packages/scipy.libs/libopenblasp-r0-23e5df77.3.21.dev.so
version: 0.3.21.dev
threading_layer: pthreads
architecture: ZenMetadata
Metadata
Assignees
Labels
Type
Projects
Status
Done