You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
sklearn.cluster.KMeans 0.23 is extra slower compared to 0.22.2 #17230
Computation in v0.22.2 was done in 2mins for whole set of explored 15 k
Actual Results
Computation takes more than 20min with exactly same data and setup as before
Also, computation even with k=1 takes very long time → compared to previous version lower k meant much faster computation
Versions
System:
python: 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)]
executable: C:\Users\micha\anaconda3\python.exe
machine: Windows-10-10.0.18362-SP0
It is but I can reproduce the timings reported in #17208 while I can't reproduce yours. That's why I'd be interested to see if the changes we propose to solve #17208 work for you as well.
I am looking for more standard solution as it is part of automated clustering UI, so I can’t force users to do these extra steps as it is a global group.
I will send you data then. How can I share data with you?
Same here. I ran an algorithm that uses kmeans on same data, scikit-learn0.22.0 took 21 minutes, 0.22.2 took 20 minutes, scikit-learn 0.23 took 45 minutes.
@beew, can you give more details, like the number of samples and features ?
We made some changes a few days ago to improve performance. You can test it by installing the nightly build of scikit-learn:
btw, I know you will not like this - to mix topics - but quick question, do you plan to move
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
to standard API as now it warns regarding deprecation in 0.24
scikit-learn does not use the system blas, but the blas shipped with scipy. So you can't switch blas with update alternatives. MKL is shipped when you install from the default channel of conda and openblas is shipped when you install from pip or from the conda-forge channel of conda
blas, but the blas shipped with scipy. So you can't switch blas with update alternatives. MKL is shipped when you install from the default channel of conda and openblas is shipped when you install from pip or from the conda-forge channel of conda
I see, I compiled numpy and scipy from source with mkl. However numpy switches blas it links to with update alternatives at run time (I have checked and the speed was different as well), so what if scikit-learn uses numpy?
I read your comment too quickly, I did not understand that you compile numpy and scipy. In that case you should be able to switch blas with update_alternatives indeed.
Scikit-learn does not ship any blas library so the output of threadpoolctl can only show the blas used by numpy and scipy. Can you reproduce that when only importing numpy or scipy ?
And indeed threadpool_info() shows all the BLAS and OpenMP runtimes that have been dynamically linked into your running Python program at the time you call the threadpool_info() function. Those libraries are typically loaded when you import numpy and scipy packages (or Cython code built with OpenMP pragmas).
So indeed if you built numpy from source against MKL, it's going to show up in the list.
I you use the master branch of threadpoolctl you can use it from the command line to show the list of linked libs you get after importing a specific Python package:
I don't understand why mkl is still linked after the switch to openblas. Maybe there are more mkl libs than libmkl_rt to switch, idk. Anyway it's independent of scikit-learn, we could probably get more information by opening an issue to numpy directly.
I don't understand why mkl is still linked after the switch to openblas. Maybe there are more mkl libs than libmkl_rt to switch, idk. Anyway it's independent of scikit-learn, we could probably get more information by opening an issue to numpy directly.
I think that is because numpy was compiled with mkl even when it is using openblas. I can see which one is being used with lsof -p | grep mkl or lsof -p | grep blas
Activity
jnothman commentedon May 15, 2020
Please provide characteristics of your dataset, at least number of samples and features
MichalRIcar commentedon May 15, 2020
jeremiedbb commentedon May 15, 2020
@MichalRIcar I can't reproduce your timings. I generated random data of shape (8950, 61) and on my laptop I have:
0.22: 43s
0.23: 32s
#17235 should be an improvement. With this I get 11s. Could you try this ?
MichalRIcar commentedon May 15, 2020
jeremiedbb commentedon May 15, 2020
It is but I can reproduce the timings reported in #17208 while I can't reproduce yours. That's why I'd be interested to see if the changes we propose to solve #17208 work for you as well.
MichalRIcar commentedon May 15, 2020
jeremiedbb commentedon May 15, 2020
You can attach a text (.txt) file in a github comment.
MichalRIcar commentedon May 15, 2020
hello, data in csv format can be downloaded from here
https://drive.google.com/open?id=1B2iAvp1Q3j0DDZemCRaR6F3vnD6K3yKS
beew commentedon May 19, 2020
Same here. I ran an algorithm that uses kmeans on same data, scikit-learn0.22.0 took 21 minutes, 0.22.2 took 20 minutes, scikit-learn 0.23 took 45 minutes.
Python 3.8.3 on Ubuntu Linux.
jeremiedbb commentedon May 19, 2020
@beew, can you give more details, like the number of samples and features ?
We made some changes a few days ago to improve performance. You can test it by installing the nightly build of scikit-learn:
jeremiedbb commentedon May 19, 2020
Could you also paste the output of:
thanks.
ogrisel commentedon May 19, 2020
You will need to
pip install threadpoolctlto execute the above.jeremiedbb commentedon May 19, 2020
threadpoolctl is a dependency of scikit-learn so it's installed when you install scikit-learn
ogrisel commentedon May 19, 2020
Indeed :)
7 remaining items
MichalRIcar commentedon May 25, 2020
btw, I know you will not like this - to mix topics - but quick question, do you plan to move
from sklearn.experimental import enable_iterative_imputer
from sklearn.impute import IterativeImputer
to standard API as now it warns regarding deprecation in 0.24
ogrisel commentedon May 25, 2020
Please open a dedicated issue for the IterativeImputer issue (if not is open already) along with the code that triggers the warning.
ogrisel commentedon May 25, 2020
Ok so part of the issue was fixed in #17235. The remainder will be tackled in #17334. Let's close this.
beew commentedon May 26, 2020
Sorry, a bit late to the party. Something happened that needed attentions.
Upgraded scikit-learn 0.23.1 it is indeed faster than 0.22.2.
With MKL
Switch to openblas with update-alternatives
I guess the mkl shows up even when update-alternatives switched to openblas because numpy was compiled with mkl.
jeremiedbb commentedon May 26, 2020
scikit-learn does not use the system blas, but the blas shipped with scipy. So you can't switch blas with update alternatives. MKL is shipped when you install from the default channel of conda and openblas is shipped when you install from pip or from the conda-forge channel of conda
beew commentedon May 26, 2020
I see, I compiled numpy and scipy from source with mkl. However numpy switches blas it links to with update alternatives at run time (I have checked and the speed was different as well), so what if scikit-learn uses numpy?
jeremiedbb commentedon May 26, 2020
I read your comment too quickly, I did not understand that you compile numpy and scipy. In that case you should be able to switch blas with update_alternatives indeed.
Scikit-learn does not ship any blas library so the output of threadpoolctl can only show the blas used by numpy and scipy. Can you reproduce that when only importing numpy or scipy ?
beew commentedon May 26, 2020
Sorry, reproduce what?
jeremiedbb commentedon May 26, 2020
The call to threadpool_info, before and after you switch blas with update alternatives.
ogrisel commentedon May 27, 2020
It depends how scipy was installed. If it comes from the system then it will probably use the system BLAS.
ogrisel commentedon May 27, 2020
And indeed
threadpool_info()shows all the BLAS and OpenMP runtimes that have been dynamically linked into your running Python program at the time you call thethreadpool_info()function. Those libraries are typically loaded when you import numpy and scipy packages (or Cython code built with OpenMP pragmas).So indeed if you built numpy from source against MKL, it's going to show up in the list.
I you use the master branch of threadpoolctl you can use it from the command line to show the list of linked libs you get after importing a specific Python package:
beew commentedon May 29, 2020
for mkl
update-alternatives to openblas
jeremiedbb commentedon May 29, 2020
I don't understand why mkl is still linked after the switch to openblas. Maybe there are more mkl libs than libmkl_rt to switch, idk. Anyway it's independent of scikit-learn, we could probably get more information by opening an issue to numpy directly.
beew commentedon May 29, 2020
I think that is because numpy was compiled with mkl even when it is using openblas. I can see which one is being used with lsof -p | grep mkl or lsof -p | grep blas