`dask_ml.cluster.SpectralClustering` does not work on the toy datasets generated by `make_blobs`
- Dominant language
- Python
- Stars
- 951
- Forks
- 262
- PR merge metrics
- No merged PRs in 30d
Description
**What happened**:
`dask_ml.cluster.SpectralClustering` does not work on the toy datasets generated by `make_blobs`.
**Minimal Complete Verifiable Example**:
```python
#!/usr/bin/env python3
from sklearn import datasets
from sklearn.cluster import MiniBatchKMeans, KMeans
import dask_ml
import dask_ml.cluster
##
def spectral_dask_est1(dataset):
input_data = dataset['input_data']
target_data = dataset['target_data']
n_clusters = dataset['n_clusters']
batch_size = 2 ** 10
estimator = MiniBatchKMeans(
batch_size=batch_size,
n_clusters=n_clusters,
max_iter=10 ** 4,
)
clf = dask_ml.cluster.SpectralClustering(
n_jobs=-1,
assign_labels=estimator,
)
clf.fit(input_data)
##
centers = 10
blobs_opts = {
"n_samples": 10**4,
"n_features": 10**4,
"centers": centers,
"random_state": 0,
}
X, y = datasets.make_blobs(**blobs_opts)
dataset = {
'input_data': X,
'target_data': y,
'n_clusters': centers,
}
spectral_dask_est1(dataset)
```
```
/Users/evar/anaconda/lib/python3.7/site-packages/dask/core.py:119: RuntimeWarning: divide by zero encountered in true_divide
return func(*(_execute_task(a, cache) for a in args))
/Users/evar/anaconda/lib/python3.7/site-packages/dask/core.py:119: RuntimeWarning: invalid value encountered in multiply
return func(*(_execute_task(a, cache) for a in args))
/Users/evar/anaconda/lib/python3.7/site-packages/dask/core.py:119: RuntimeWarning: invalid value encountered in true_divide
return func(*(_execute_task(a, cache) for a in args))
Traceback (most recent call last):
File "/Users/evar/Base/_Code/uni/soal_playground/src_py/t_spectral_dask.py", line 43, in
spectral_dask_est1(dataset)
File "/Users/evar/Base/_Code/uni/soal_playground/src_py/t_spectral_dask.py", line 26, in spectral_dask_est1
clf.fit(input_data)
File "/Users/evar/anaconda/lib/python3.7/site-packages/dask_ml/cluster/spectral.py", line 301, in fit
km.fit(U2)
File "/Users/evar/anaconda/lib/python3.7/site-packages/sklearn/cluster/_kmeans.py", line 1899, in fit
accept_large_sparse=False,
File "/Users/evar/anaconda/lib/python3.7/site-packages/sklearn/base.py", line 566, in _validate_data
X = check_array(X, **check_params)
File "/Users/evar/anaconda/lib/python3.7/site-packages/sklearn/utils/validation.py", line 800, in check_array
_assert_all_finite(array, allow_nan=force_all_finite == "allow-nan")
File "/Users/evar/anaconda/lib/python3.7/site-packages/sklearn/utils/validation.py", line 116, in _assert_all_finite
type_err, msg_dtype if msg_dtype is not None else X.dtype
ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
```
**Environment**:
```
dask==2022.1.0
dask-glm==0.2.0
dask-ml==2022.1.22
dask-xgboost==0.1.10
scikit-learn==1.0.2
scipy==1.6.2
```
- Python version: 3.7.7
- Operating System: tested with both macOS and Ubuntu
- Install method (conda, pip, source): pip
Contributor guide
Research direction
Start by reproducing the provided make_blobs example with the listed package versions, then inspect dask_ml/cluster/spectral.py around fit and the reported km.fit(U2) failure. Determine why the generated embedding contains NaN or infinity, and verify that SpectralClustering fits this dataset without invalid values or the reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, scikit-learn
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100