question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error if using dask_ml.preprocessing RobustScaler

See original GitHub issue

I want to use RobustScaler and got following error:

Traceback (most recent call last):
  File "<input>", line 14, in <module>
  File "/home/magehex/anaconda3/envs/reinbo/lib/python3.7/site-packages/sklearn/base.py", line 556, in fit_transform
    return self.fit(X, y, **fit_params).transform(X)
  File "/home/magehex/anaconda3/envs/reinbo/lib/python3.7/site-packages/dask_ml/preprocessing/data.py", line 180, in fit
    quantiles = [da.percentile(col, [q_min, 50.0, q_max]) for col in X.T]
  File "/home/magehex/anaconda3/envs/reinbo/lib/python3.7/site-packages/dask_ml/preprocessing/data.py", line 180, in <listcomp>
    quantiles = [da.percentile(col, [q_min, 50.0, q_max]) for col in X.T]
  File "/home/magehex/anaconda3/envs/reinbo/lib/python3.7/site-packages/dask/array/percentile.py", line 133, in percentile
    for i, key in enumerate(a.__dask_keys__())
AttributeError: 'numpy.ndarray' object has no attribute '__dask_keys__'

Code:

import numpy as np
from dask_ml.preprocessing import RobustScaler
import time
from sklearn.datasets.samples_generator import make_blobs

# generate 2d classification dataset
X, y = make_blobs(n_samples=100000, centers=2, n_features=380)

X_train = X.astype(np.float32)
y_train = y.astype(np.int32)

start = time.time()

RobustScaler().fit_transform(X_train,y_train)

end = time.time()
print(end - start)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stsievertcommented, Nov 13, 2019

as a user, what’s less surprising? [choices]

I think both are surprising. The results don’t match Scikit-learn’s results in either case.

I like the approach in https://github.com/dask/dask-ml/pull/580#issuecomment-549077034: raise an error saying “use Scikit-learn. If you have to, you can wrap in a Dask array, but that’ll yield slower/approximate results”: https://github.com/dask/dask-ml/blob/7793962d990a4b5290a5cfd1aee1d5b48828f1a1/dask_ml/decomposition/pca.py#L18-L24

That presents some challenges for pipelines with Dask-ML estimators and Dask array inputs. What if RobustScaler is an element in that pipeline? Maybe there should be a wrapper class to take Dask inputs, call the corresponding Scikit-learn estimator with a NumPy array and return a Dask output?

0reactions
TomAugspurgercommented, Nov 10, 2019

So, as a user, what’s less surprising?

  1. A NumPy array giving a different answer to the same Dask array with the block?
  2. Our estimator giving a different output to sklearns on the same numpy array?
Read more comments on GitHub >

github_iconTop Results From Across the Web

dask_ml.preprocessing.RobustScaler - Dask-ML
Scale features using statistics that are robust to outliers. This Scaler removes the median and scales the data according to the quantile range...
Read more >
Preprocessing — dask-ml 2022.5.28 documentation
preprocessing contains some scikit-learn style transformers that can be used in Pipelines to perform various data transformations as part of the model fitting ......
Read more >
dask_ml.metrics.mean_absolute_percentage_error - Dask-ML
Returns a full set of errors in case of multioutput input. 'uniform_average' : Errors of all outputs are averaged with uniform weight. computebool....
Read more >
dask_ml.metrics.mean_squared_error - Dask-ML
Errors of all outputs are averaged with uniform weight. squaredbool, default=True. If True returns MSE value, if False returns RMSE value. Returns.
Read more >
API Reference — dask-ml 2022.5.28 documentation
Transforms features using quantile information. preprocessing.Categorizer ([categories, columns]). Transform columns of a DataFrame to categorical dtype.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found