diff --git a/.gitignore b/.gitignore index f11233a..046dd12 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,4 @@ .idea/* .vscode/* test/experiments.jl -/extras/.ipynb_checkpoints/* -.Rproj.user +/extras/.ipynb_checkpoints/* \ No newline at end of file diff --git a/Project.toml b/Project.toml index 71f0212..52e290c 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ParallelKMeans" uuid = "42b8e9d4-006b-409a-8472-7f34b3fb58af" authors = ["Bernard Brenyah", "Andrey Oskin"] -version = "1.0.0" +version = "0.2.2" [deps] Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7" diff --git a/README.md b/README.md index 90c8a3d..684f5c6 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,7 @@ [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://PyDataBlog.github.io/ParallelKMeans.jl/stable) [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://PyDataBlog.github.io/ParallelKMeans.jl/dev) -[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac) -[![Build Status](https://github.com/PyDataBlog/ParallelKMeans.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/PyDataBlog/ParallelKMeans.jl/actions) +[![Build Status](https://github.com/PyDataBlog/ParallelKMeans.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/PyDataBlog/ParallelKMeans.jl/actions/workflows/CI.yml/badge.svg) [![codecov](https://codecov.io/gh/PyDataBlog/ParallelKMeans.jl/branch/master/graph/badge.svg?token=799USS6BPH)](https://codecov.io/gh/PyDataBlog/ParallelKMeans.jl) [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FPyDataBlog%2FParallelKMeans.jl.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FPyDataBlog%2FParallelKMeans.jl?ref=badge_shield) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/PyDataBlog/ParallelKMeans.jl/master) diff --git a/docs/src/benchmark_image.png b/docs/src/benchmark_image.png index 3d194f4..af2b829 100644 Binary files a/docs/src/benchmark_image.png and b/docs/src/benchmark_image.png differ diff --git a/docs/src/index.md b/docs/src/index.md index bb2d3cd..03cc9e3 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -79,15 +79,14 @@ pkg> free ParallelKMeans - [X] Support for weighted K-means. - [X] Support of MLJ Random generation hyperparameter. - [X] Implementation of [Mini-batch KMeans variant](https://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf) -- [X] Add contribution guidelines. - [ ] Support for other distance metrics supported by [Distances.jl](https://github.com/JuliaStats/Distances.jl#supported-distances). - [ ] Implementation of [Geometric methods to accelerate k-means algorithm](http://cs.baylor.edu/~hamerly/papers/sdm2016_rysavy_hamerly.pdf). - [ ] Native support for tabular data inputs outside of MLJModels' interface. +- [ ] GPU support? - [ ] Distributed calculations support. -- [ ] Further optimization of code base. -- [ ] Improved Documentation with more tutorials. +- [ ] Optimization of code base. +- [ ] Improved Documentation - [ ] More benchmark tests. -- [ ] GPU support? ## How To Use @@ -128,7 +127,7 @@ r.converged # whether the procedure converged - [Elkan()](https://www.aaai.org/Papers/ICML/2003/ICML03-022.pdf) - Recommended for high dimensional data. - [Yinyang()](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/ding15.pdf) - Recommended for large dimensions and/or large number of clusters. - [Coreset()](http://proceedings.mlr.press/v51/lucic16-supp.pdf) - Recommended for very fast clustering of very large datasets, when extreme accuracy is not important. -- [MiniBatch()](https://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf) - Recommended for extremely large datasets, when extreme accuracy is not important. *Experimental Implementation* +- [MiniBatch()](https://www.eecs.tufts.edu/~dsculley/papers/fastkmeans.pdf) - Recommended for extremely large datasets, when extreme accuracy is not important. - [Geometric()](http://cs.baylor.edu/~hamerly/papers/sdm2016_rysavy_hamerly.pdf) - (Coming soon) ### Practical Usage Examples @@ -188,17 +187,17 @@ Currently, the benchmark speed tests are based on the search for optimal number _________________________________________________________________________________________________________ -|1 million sample (secs)|100k sample (secs)|10k sample (secs)|1k sample (secs)|package |language |process | -|-----------------------|------------------|-----------------|----------------|------------------------|-----------|----------| -|282.7 |15.27 |0.7324 |0.01682 |Knor |R |full scan | -|854 |87 |6.11 |0.000719 |Sklearn KMeans |Python |full scan | -|11.2 |1.41 |0.000317 |0.000141 |Sklearn MiniBatch Kmeans|Python |stochastic| -|254.481 |18.517 |0.000794956 |0.000031211 |Mlpack |C++ Wrapper|full scan | -|653.178 |45.468 |0.000824115 |0.000017301 |Clustering.jl |Julia |full scan | -|19.955 |2.758 |0.000166957 |0.000009206 |ParallelKMeans Lloyd |Julia |full scan | -|11.234 |1.654 |0.000109074 |0.000012819 |ParallelKMeans Hamerly |Julia |full scan | -|19.394 |1.436 |0.000109262 |0.000013726 |ParallelKMeans Elkan |Julia |full scan | -|14.080 |0.000972914 |0.000095325 |0.000009802 |ParallelKMeans YingYang |Julia |full scan | +|1 million sample (secs)|100k sample (secs)|10k sample (secs)|1k sample (secs)|package |language | +|:---------------------:|:----------------:|:---------------:|:--------------:|:---------------------:|:---------:| +| 538.53100 | 33.15700 | 0.74238 | 0.01710 | Clustering.jl | Julia | +| 220.35700 | 20.93600 | 0.82430 | 0.02639 | mlpack |C++ Wrapper| +| 20.55400 | 2.91300 | 0.17559 | 0.00609 | Lloyd | Julia | +| 11.51800 | 0.96637 | 0.09990 | 0.00635 | Hamerly | Julia | +| 14.01900 | 1.13100 | 0.07912 | 0.00646 | Elkan | Julia | +| 9.97000 | 1.14600 | 0.10834 | 0.00704 | Yinyang | Julia | +| 1,430.00000 | 146.00000 | 5.77000 | 0.34400 | Sklearn KMeans | Python | +| 30.10000 | 3.75000 | 0.61300 | 0.20100 |Sklearn MiniBatchKMeans| Python | +| 218.20000 | 15.51000 | 0.73370 | 0.01947 | Knor | R | _________________________________________________________________________________________________________ @@ -215,14 +214,15 @@ ________________________________________________________________________________ - 0.1.8 Minor cleanup - 0.1.9 Added travis support for Julia 1.5 - 0.2.0 Updated MLJ Interface -- 0.2.1 Initial Mini-batch implementation -- 0.2.2 Updated MLJInterface -- 1.0.0 Stable public release +- 0.2.1 Mini-batch implementation ## Contributing Ultimately, we see this package as potentially the one-stop-shop for everything related to KMeans algorithm and its speed up variants. We are open to new implementations and ideas from anyone interested in this project. -This project adopts the [ColPrac community guidelines](https://github.com/SciML/ColPrac). + +Detailed contribution guidelines will be added in upcoming releases. + + ```@index ``` diff --git a/extras/ClusteringJL, Mlpack, & ParallelKMeans Benchmarks Final.ipynb b/extras/ClusteringJL, Mlpack, & ParallelKMeans Benchmarks Final.ipynb index 0aeff59..2b264ac 100644 --- a/extras/ClusteringJL, Mlpack, & ParallelKMeans Benchmarks Final.ipynb +++ b/extras/ClusteringJL, Mlpack, & ParallelKMeans Benchmarks Final.ipynb @@ -157,12 +157,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 254.481 s (93 allocations: 2.08 GiB)\n" + " 220.357 s (85 allocations: 2.08 GiB)\n" ] } ], "source": [ - "@btime [mlpack.kmeans(i, $X_1m_mlp; algorithm=\"hamerly\", max_iterations=100_000)[1] for i = 2:10];" + "@btime [mlpack.kmeans(i, $X_1m_mlp; algorithm=\"hamerly\", max_iterations=1000)[1] for i = 2:10];" ] }, { @@ -174,12 +174,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 18.517 s (93 allocations: 212.88 MiB)\n" + " 20.936 s (85 allocations: 212.88 MiB)\n" ] } ], "source": [ - "@btime [mlpack.kmeans(i, $X_100k_mlp; algorithm=\"hamerly\", max_iterations=100_000)[1] for i = 2:10];" + "@btime [mlpack.kmeans(i, $X_100k_mlp; algorithm=\"hamerly\", max_iterations=1000)[1] for i = 2:10];" ] }, { @@ -191,12 +191,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 794.956 ms (93 allocations: 21.30 MiB)\n" + " 824.295 ms (85 allocations: 21.30 MiB)\n" ] } ], "source": [ - "@btime [mlpack.kmeans(i, $X_10k_mlp; algorithm=\"hamerly\", max_iterations=100_000)[1] for i = 2:10];" + "@btime [mlpack.kmeans(i, $X_10k_mlp; algorithm=\"hamerly\", max_iterations=1000)[1] for i = 2:10];" ] }, { @@ -208,12 +208,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 31.211 ms (93 allocations: 2.14 MiB)\n" + " 26.388 ms (85 allocations: 2.14 MiB)\n" ] } ], "source": [ - "@btime [mlpack.kmeans(i, $X_1k_mlp; algorithm=\"hamerly\", max_iterations=100_000)[1] for i = 2:10];" + "@btime [mlpack.kmeans(i, $X_1k_mlp; algorithm=\"hamerly\", max_iterations=1000)[1] for i = 2:10];" ] }, { @@ -239,12 +239,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 653.178 s (21031 allocations: 39.26 GiB)\n" + " 538.531 s (31820 allocations: 33.24 GiB)\n" ] } ], "source": [ - "@btime [Clustering.kmeans($X_1m, i; tol=1e-6, maxiter=100_000).totalcost for i = 2:10];" + "@btime [Clustering.kmeans($X_1m, i; tol=1e-6, maxiter=1000).totalcost for i = 2:10];" ] }, { @@ -256,12 +256,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 45.468 s (14876 allocations: 2.78 GiB)\n" + " 33.157 s (20032 allocations: 2.13 GiB)\n" ] } ], "source": [ - "@btime [Clustering.kmeans($X_100k, i; tol=1e-6, maxiter=100_000).totalcost for i = 2:10];" + "@btime [Clustering.kmeans($X_100k, i; tol=1e-6, maxiter=1000).totalcost for i = 2:10];" ] }, { @@ -273,12 +273,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 824.115 ms (4294 allocations: 83.90 MiB)\n" + " 742.375 ms (7614 allocations: 82.82 MiB)\n" ] } ], "source": [ - "@btime [Clustering.kmeans($X_10k, i; tol=1e-6, maxiter=100_000).totalcost for i = 2:10]; " + "@btime [Clustering.kmeans($X_10k, i; tol=1e-6, maxiter=1000).totalcost for i = 2:10]; " ] }, { @@ -290,12 +290,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 17.301 ms (767 allocations: 2.24 MiB)\n" + " 17.098 ms (1699 allocations: 2.34 MiB)\n" ] } ], "source": [ - "@btime [Clustering.kmeans($X_1k, i; tol=1e-6, maxiter=100_000).totalcost for i = 2:10]; " + "@btime [Clustering.kmeans($X_1k, i; tol=1e-6, maxiter=1000).totalcost for i = 2:10]; " ] }, { @@ -328,12 +328,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 19.955 s (40915 allocations: 140.36 MiB)\n" + " 20.554 s (40737 allocations: 210.10 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Lloyd(), $X_1m, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Lloyd(), $X_1m, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -345,12 +345,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 2.758 s (52724 allocations: 17.65 MiB)\n" + " 2.913 s (56992 allocations: 26.27 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Lloyd(), $X_100k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Lloyd(), $X_100k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -362,12 +362,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 166.957 ms (31942 allocations: 3.80 MiB)\n" + " 175.590 ms (34558 allocations: 5.56 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Lloyd(), $X_10k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Lloyd(), $X_10k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -379,12 +379,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 9.206 ms (9792 allocations: 987.77 KiB)\n" + " 6.093 ms (10349 allocations: 1.35 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Lloyd(), $X_1k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Lloyd(), $X_1k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -403,12 +403,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 11.234 s (50446 allocations: 278.97 MiB)\n" + " 11.518 s (62467 allocations: 350.25 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Hamerly(), $X_1m, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Hamerly(), $X_1m, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -420,12 +420,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 1.654 s (85374 allocations: 34.73 MiB)\n" + " 966.373 ms (58405 allocations: 40.85 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Hamerly(), $X_100k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Hamerly(), $X_100k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -437,12 +437,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 109.074 ms (51352 allocations: 7.16 MiB)\n" + " 99.897 ms (61185 allocations: 10.27 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Hamerly(), $X_10k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Hamerly(), $X_10k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -456,12 +456,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 12.819 ms (16050 allocations: 1.72 MiB)\n" + " 6.350 ms (16373 allocations: 2.25 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Hamerly(), $X_1k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Hamerly(), $X_1k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -487,12 +487,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 19.394 s (65605 allocations: 632.12 MiB)\n" + " 14.019 s (55965 allocations: 701.39 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Elkan(), $X_1m, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Elkan(), $X_1m, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -504,12 +504,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 1.436 s (57010 allocations: 67.54 MiB)\n" + " 1.131 s (50298 allocations: 75.12 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Elkan(), $X_100k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Elkan(), $X_100k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -521,12 +521,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 109.262 ms (48980 allocations: 10.48 MiB)\n" + " 79.120 ms (49220 allocations: 12.43 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Elkan(), $X_10k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Elkan(), $X_10k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -540,12 +540,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 13.726 ms (16348 allocations: 2.10 MiB)\n" + " 6.464 ms (16613 allocations: 2.61 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Elkan(), $X_1k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Elkan(), $X_1k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -571,12 +571,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 14.080 s (31669 allocations: 277.54 MiB)\n" + " 9.970 s (23622 allocations: 346.02 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_1m, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_1m, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -588,12 +588,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 972.914 ms (24387 allocations: 29.71 MiB)\n" + " 1.146 s (31409 allocations: 37.89 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_100k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_100k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -605,12 +605,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 95.325 ms (23881 allocations: 4.96 MiB)\n" + " 108.337 ms (24498 allocations: 6.24 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_10k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_10k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -622,12 +622,12 @@ "name": "stdout", "output_type": "stream", "text": [ - " 9.802 ms (8812 allocations: 1.15 MiB)\n" + " 7.044 ms (9805 allocations: 1.53 MiB)\n" ] } ], "source": [ - "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_1k, i; tol=1e-6, max_iters=100_000, verbose=false).totalcost for i = 2:10];" + "@btime [ParallelKMeans.kmeans(Yinyang(7), $X_1k, i; tol=1e-6, max_iters=1000, verbose=false).totalcost for i = 2:10];" ] }, { @@ -640,15 +640,15 @@ ], "metadata": { "kernelspec": { - "display_name": "Julia 1.6.1", + "display_name": "Julia 1.4.1", "language": "julia", - "name": "julia-1.6" + "name": "julia-1.4" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "1.6.1" + "version": "1.4.1" }, "nteract": { "version": "0.22.4" diff --git a/extras/Sklearn Benchmark-Final-MiniBatch.ipynb b/extras/Sklearn Benchmark-Final-MiniBatch.ipynb index 928c9f0..69d8767 100644 --- a/extras/Sklearn Benchmark-Final-MiniBatch.ipynb +++ b/extras/Sklearn Benchmark-Final-MiniBatch.ipynb @@ -9,30 +9,21 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:14:13.423924Z", "start_time": "2020-04-03T11:14:13.040511Z" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The watermark extension is already loaded. To reload it, use:\n", - " %reload_ext watermark\n" - ] - } - ], + "outputs": [], "source": [ "%load_ext watermark" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:14:16.497814Z", @@ -44,21 +35,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "Python implementation: CPython\n", - "Python version : 3.9.2\n", - "IPython version : 7.22.0\n", + "Fri Apr 03 2020 \n", "\n", - "numpy : 1.20.2\n", - "sklearn: 0.24.1\n", + "CPython 3.7.6\n", + "IPython 7.13.0\n", "\n", - "Compiler : Clang 11.0.1 \n", - "OS : Darwin\n", - "Release : 20.4.0\n", - "Machine : x86_64\n", - "Processor : i386\n", - "CPU cores : 6\n", - "Architecture: 64bit\n", - "\n" + "numpy 1.18.1\n", + "sklearn 0.22.2.post1\n", + "\n", + "compiler : Clang 9.0.1 \n", + "system : Darwin\n", + "release : 19.3.0\n", + "machine : x86_64\n", + "processor : i386\n", + "CPU cores : 6\n", + "interpreter: 64bit\n" ] } ], @@ -82,7 +73,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:14:18.529474Z", @@ -100,7 +91,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:14:18.533119Z", @@ -114,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:14:18.862787Z", @@ -129,6 +120,30 @@ "X_1k = np.random.rand(1_000, 30)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Export Data For Other Languages" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "ExecuteTime": { + "end_time": "2020-04-03T11:14:42.853811Z", + "start_time": "2020-04-03T11:14:18.864713Z" + } + }, + "outputs": [], + "source": [ + "np.savetxt('data_1m.csv', X_1m, delimiter=',')\n", + "np.savetxt('data_100k.csv', X_100k, delimiter=',')\n", + "np.savetxt('data_10k.csv', X_10k, delimiter=',')\n", + "np.savetxt('data_1k.csv', X_1k, delimiter=',')" + ] + }, { "cell_type": "code", "execution_count": null, @@ -152,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:14:42.860735Z", @@ -169,12 +184,7 @@ " ss = []\n", " for i in range(2, 11):\n", "\n", - " model = MiniBatchKMeans(n_clusters=i,\n", - " init='k-means++',\n", - " tol=1e-6, \n", - " max_no_improvement=10,\n", - " max_iter=100_000).fit(x)\n", - " \n", + " model = MiniBatchKMeans(n_clusters=i, init='k-means++', max_iter=1000).fit(x)\n", " ss.append(model.inertia_)\n", " \n", " return ss" @@ -182,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:18:44.528214Z", @@ -194,7 +204,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "11.2 s ± 1.42 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "30.1 s ± 2.48 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -204,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:19:13.998841Z", @@ -216,7 +226,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1.41 s ± 168 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "3.75 s ± 405 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -226,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:19:18.915146Z", @@ -238,7 +248,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "317 ms ± 32.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "613 ms ± 45 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -248,7 +258,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:19:20.542884Z", @@ -260,7 +270,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "141 ms ± 1.88 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n" + "201 ms ± 14.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -291,7 +301,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:19:50.034488Z", @@ -302,18 +312,18 @@ { "data": { "text/plain": [ - "[2445867.479686552,\n", - " 2412165.7171342387,\n", - " 2385104.140258503,\n", - " 2357469.335790009,\n", - " 2340276.2532835295,\n", - " 2321510.4619055036,\n", - " 2311584.688176011,\n", - " 2290377.712416416,\n", - " 2277367.844858403]" + "[2447844.622163797,\n", + " 2410065.3115257025,\n", + " 2382870.705802254,\n", + " 2357328.667334357,\n", + " 2340856.721208137,\n", + " 2323608.3094369015,\n", + " 2308229.727174064,\n", + " 2290479.2838455164,\n", + " 2277841.943680881]" ] }, - "execution_count": 25, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -324,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:19:53.759199Z", @@ -335,18 +345,18 @@ { "data": { "text/plain": [ - "[244482.59885062292,\n", - " 240816.03776186175,\n", - " 237910.97134228173,\n", - " 236027.32053503324,\n", - " 234021.78786939755,\n", - " 231831.28918362648,\n", - " 230429.8308173524,\n", - " 229400.1630608017,\n", - " 227886.7518947741]" + "[244844.82795721738,\n", + " 240826.34373045812,\n", + " 238007.0239377424,\n", + " 235703.69897529576,\n", + " 233968.6199870226,\n", + " 231772.27469308046,\n", + " 230237.945394652,\n", + " 228795.61081951743,\n", + " 228469.0079741194]" ] }, - "execution_count": 26, + "execution_count": 13, "metadata": {}, "output_type": "execute_result" } @@ -357,7 +367,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:19:54.363978Z", @@ -368,18 +378,18 @@ { "data": { "text/plain": [ - "[24392.745661181747,\n", - " 23987.646437792417,\n", - " 23697.726153370553,\n", - " 23426.952006343166,\n", - " 23276.90790158953,\n", - " 23064.17230258268,\n", - " 22954.647209537172,\n", - " 22722.318449295362,\n", - " 22708.263604056046]" + "[24348.763173523337,\n", + " 24001.890978658197,\n", + " 23684.223413130192,\n", + " 23454.91855690728,\n", + " 23269.213047246023,\n", + " 23120.88619672152,\n", + " 22868.42252728833,\n", + " 22738.258512791606,\n", + " 22573.987681140177]" ] }, - "execution_count": 27, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -390,7 +400,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2020-04-03T11:19:54.565865Z", @@ -401,18 +411,18 @@ { "data": { "text/plain": [ - "[2431.933005539147,\n", - " 2382.703412642692,\n", - " 2350.0513505820563,\n", - " 2317.982091752885,\n", - " 2294.633919025983,\n", - " 2274.200812255565,\n", - " 2242.548182527589,\n", - " 2221.944884143639,\n", - " 2205.5533905720613]" + "[2427.133269064922,\n", + " 2385.534105444017,\n", + " 2344.84192128042,\n", + " 2310.5402444073848,\n", + " 2285.2629922427886,\n", + " 2270.897261587013,\n", + " 2242.0384501089516,\n", + " 2226.0452902526335,\n", + " 2204.5812780067554]" ] }, - "execution_count": 28, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -438,7 +448,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.2" + "version": "3.7.6" }, "nteract": { "version": "0.22.0" diff --git a/extras/Sklearn Benchmark-Final.ipynb b/extras/Sklearn Benchmark-Final.ipynb index 8842b83..fd2e5c3 100644 --- a/extras/Sklearn Benchmark-Final.ipynb +++ b/extras/Sklearn Benchmark-Final.ipynb @@ -35,21 +35,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "Python implementation: CPython\n", - "Python version : 3.9.2\n", - "IPython version : 7.22.0\n", + "Wed Apr 01 2020 \n", "\n", - "numpy : 1.20.2\n", - "sklearn: 0.24.1\n", + "CPython 3.7.6\n", + "IPython 7.13.0\n", "\n", - "Compiler : Clang 11.0.1 \n", - "OS : Darwin\n", - "Release : 20.4.0\n", - "Machine : x86_64\n", - "Processor : i386\n", - "CPU cores : 6\n", - "Architecture: 64bit\n", - "\n" + "numpy 1.18.1\n", + "sklearn 0.22.2.post1\n", + "\n", + "compiler : Clang 9.0.1 \n", + "system : Darwin\n", + "release : 19.3.0\n", + "machine : x86_64\n", + "processor : i386\n", + "CPU cores : 6\n", + "interpreter: 64bit\n" ] } ], @@ -57,6 +57,13 @@ "%watermark -m -v -n -p numpy,sklearn" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -151,15 +158,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "ClusteringJL, Mlpack, & ParallelKMeans Benchmarks Final.ipynb\r\n", - "Sklearn Benchmark-Final-MiniBatch.ipynb\r\n", + "ClusteringJL & ParallelKMeans Benchmarks.ipynb\r\n", "Sklearn Benchmark-Final.ipynb\r\n", + "Sklearn Benchmark.ipynb\r\n", "data_100k.csv\r\n", "data_10k.csv\r\n", "data_1k.csv\r\n", "data_1m.csv\r\n", - "knor_final.Rmd\r\n", - "knor_final.pdf\r\n" + "knor_benchmark.ipynb\r\n" ] } ], @@ -167,6 +173,13 @@ "%ls" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -195,14 +208,13 @@ "def test_multicore_speed(x):\n", " \"\"\"\n", " Just a convenient function to select the number of cluster groups based \n", - " on the elbow method. \n", - " Requries testing 2 to 10 k ranges using all available cores (default in sklearn > 0.24).\n", + " on the elbow method. Requries testing 2 to 10 k ranges using all available cores.\n", " \"\"\"\n", " ss = []\n", " for i in range(2, 11):\n", "\n", " model = KMeans(n_clusters=i, init='k-means++',\n", - " max_iter=100_000, tol=1e-6).fit(x)\n", + " max_iter=1000, tol=1e-6, n_jobs=-1).fit(x)\n", " \n", " ss.append(model.inertia_)\n", " \n", @@ -220,35 +232,33 @@ }, "outputs": [ { - "name": "stdout", + "name": "stderr", "output_type": "stream", "text": [ - "CPU times: user 1h 18min 54s, sys: 58.2 s, total: 1h 19min 52s\n", - "Wall time: 14min 14s\n" + "/Users/mysterio/miniconda3/envs/pydata/lib/python3.7/site-packages/joblib/externals/loky/process_executor.py:706: UserWarning: A worker stopped while some jobs were given to the executor. This can be caused by a too short worker timeout or by a memory leak.\n", + " \"timeout or by a memory leak.\", UserWarning\n", + "/Users/mysterio/miniconda3/envs/pydata/lib/python3.7/site-packages/joblib/externals/loky/process_executor.py:706: UserWarning: A worker stopped while some jobs were given to the executor. This can be caused by a too short worker timeout or by a memory leak.\n", + " \"timeout or by a memory leak.\", UserWarning\n", + "/Users/mysterio/miniconda3/envs/pydata/lib/python3.7/site-packages/joblib/externals/loky/process_executor.py:706: UserWarning: A worker stopped while some jobs were given to the executor. This can be caused by a too short worker timeout or by a memory leak.\n", + " \"timeout or by a memory leak.\", UserWarning\n", + "/Users/mysterio/miniconda3/envs/pydata/lib/python3.7/site-packages/joblib/externals/loky/process_executor.py:706: UserWarning: A worker stopped while some jobs were given to the executor. This can be caused by a too short worker timeout or by a memory leak.\n", + " \"timeout or by a memory leak.\", UserWarning\n", + "/Users/mysterio/miniconda3/envs/pydata/lib/python3.7/site-packages/joblib/externals/loky/process_executor.py:706: UserWarning: A worker stopped while some jobs were given to the executor. This can be caused by a too short worker timeout or by a memory leak.\n", + " \"timeout or by a memory leak.\", UserWarning\n", + "/Users/mysterio/miniconda3/envs/pydata/lib/python3.7/site-packages/joblib/externals/loky/process_executor.py:706: UserWarning: A worker stopped while some jobs were given to the executor. This can be caused by a too short worker timeout or by a memory leak.\n", + " \"timeout or by a memory leak.\", UserWarning\n" ] }, { - "data": { - "text/plain": [ - "[2437341.7270931103,\n", - " 2399351.127290113,\n", - " 2368831.2054143585,\n", - " 2346201.222251802,\n", - " 2326790.6041440214,\n", - " 2309585.672550795,\n", - " 2293413.1789655103,\n", - " 2280334.331886036,\n", - " 2267961.2758927774]" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "23min 50s ± 37.3 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + ] } ], "source": [ - "# takes days with timeit\n", - "%time test_multicore_speed(X_1m)" + "%timeit test_multicore_speed(X_1m)" ] }, { @@ -265,7 +275,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1min 27s ± 2.37 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "2min 26s ± 10.5 s per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -287,7 +297,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "6.11 s ± 407 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "5.77 s ± 190 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -309,7 +319,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "719 ms ± 16.2 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" + "344 ms ± 26.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)\n" ] } ], @@ -351,15 +361,15 @@ { "data": { "text/plain": [ - "[2437324.235389248,\n", - " 2399413.0830678497,\n", - " 2368818.8267027903,\n", - " 2346299.9410698186,\n", - " 2326735.440058622,\n", - " 2309516.949678505,\n", - " 2293478.379922331,\n", - " 2280295.348438886,\n", - " 2267882.6124851117]" + "[2437387.415492945,\n", + " 2399339.992032868,\n", + " 2368871.465710383,\n", + " 2346462.0070933346,\n", + " 2326813.1069245334,\n", + " 2309414.654713539,\n", + " 2293462.201313399,\n", + " 2280445.3099815217,\n", + " 2267931.587844557]" ] }, "execution_count": 13, @@ -384,15 +394,15 @@ { "data": { "text/plain": [ - "[243589.2873161867,\n", - " 239764.75364587895,\n", - " 236710.75522105594,\n", - " 234408.93214474779,\n", - " 232424.07131403798,\n", - " 230670.0302232603,\n", - " 229006.70085774802,\n", - " 227697.49490115896,\n", - " 226417.04919758317]" + "[243589.31245874695,\n", + " 239767.31925266725,\n", + " 236726.38550223835,\n", + " 234442.93793080037,\n", + " 232422.69835603604,\n", + " 230691.21321680304,\n", + " 229058.01186924183,\n", + " 227682.08176776656,\n", + " 226431.94988426092]" ] }, "execution_count": 14, @@ -417,15 +427,15 @@ { "data": { "text/plain": [ - "[24258.313108868635,\n", - " 23866.423212883026,\n", - " 23549.056659001235,\n", - " 23281.743553533157,\n", - " 23075.514042452258,\n", - " 22868.84837785622,\n", - " 22703.89545928599,\n", - " 22543.180090006244,\n", - " 22388.36033844091]" + "[24258.330630805453,\n", + " 23867.89675877502,\n", + " 23551.140681476474,\n", + " 23293.288967365683,\n", + " 23061.19983962278,\n", + " 22875.664074825218,\n", + " 22696.46474595464,\n", + " 22537.26870504501,\n", + " 22386.635745851694]" ] }, "execution_count": 15, @@ -450,15 +460,15 @@ { "data": { "text/plain": [ - "[2416.426793583685,\n", - " 2363.360485189129,\n", - " 2323.6350017094774,\n", - " 2289.0280235978544,\n", - " 2257.950426505983,\n", - " 2238.313140590653,\n", - " 2212.847741952131,\n", - " 2191.168916233091,\n", - " 2172.246861197593]" + "[2415.7676706737066,\n", + " 2363.5037202047565,\n", + " 2325.6642970049497,\n", + " 2290.4172039328205,\n", + " 2259.749823733678,\n", + " 2233.0460105250836,\n", + " 2209.553788815628,\n", + " 2183.6662205376624,\n", + " 2172.285836431226]" ] }, "execution_count": 16, @@ -494,7 +504,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.2" + "version": "3.7.6" }, "nteract": { "version": "0.22.0" diff --git a/extras/benchmark_plot.jl b/extras/benchmark_plot.jl deleted file mode 100644 index 9587292..0000000 --- a/extras/benchmark_plot.jl +++ /dev/null @@ -1,64 +0,0 @@ -using Plots -using CSV -using DataFrames -using Chain - - -data = CSV.read("extras/updated_benchmarks_may_1.csv", DataFrame) - -#data2 = stack(data, 1:4) -#unstack(data2, :variable, :package, :value) |> CSV.write("extras/wide.csv") - -long_data = @chain data begin - rename(_, [replace(x, " " => "_") for x in names(_)]) - rename(_, [replace(x, "_sample_(secs)" => "") for x in names(_)]) - filter(:process => !=("stochastic"), _) - stack(_, 1:4) -end - -color_map = Dict{String, Int}() - -for (idx, val) in enumerate(unique(long_data.package)) - push!(color_map, val => idx) -end - -assign_linestyle(x) = occursin("ParallelKMeans", x) ? :solid : :dashdot - -function assign_rank(x) - if x == "1_million" - return 4 - elseif x == "100k" - return 3 - elseif x == "10k" - return 2 - elseif x == "1k" - return 1 - end -end - -long_data[:, "linestyle"] = assign_linestyle.(long_data.package); -long_data[:, "rank"] = assign_rank.(long_data.variable); - - -plt = plot(title = "Elbow Method Benchmark Results", - yaxis=:log, - palette=:seaborn_deep, - size=(1000, 700), - ylabel="Execution Time (in seconds - logged)", - yrotation=30, - xlabel="Sample Sizes", - legend=:topleft) - -for pkg in unique(long_data.package) - pkg_data = filter(:package => ==(pkg), long_data) - sort!(pkg_data, order(:rank, rev=false)) - plot!(pkg_data.variable, - pkg_data.value, - lw=3, - linestyle=pkg_data.linestyle, - label=pkg, - color=color_map[pkg]) - scatter!(pkg_data.variable, pkg_data.value, markersize=4, color=color_map[pkg], label="") -end - -display(plt) diff --git a/extras/knor_final.Rmd b/extras/knor_final.Rmd index ed10549..eb90e0e 100644 --- a/extras/knor_final.Rmd +++ b/extras/knor_final.Rmd @@ -13,16 +13,6 @@ output: library(knor) ``` - -```{r} -## Installed packages -installed.packages()[names(sessionInfo()$otherPkgs), "Version"] -``` -```{r} -## R Version -version[['version.string']] -``` - ```{r} X_1m = as.matrix(read.csv("data_1m.csv", header = FALSE)) ``` @@ -53,7 +43,7 @@ test_multicore_speed <- function(x){ for (i in rng) { m <- knor::Kmeans(data = x, centers = i, - iter.max = 100000, nthread = -1, + iter.max = 1000, nthread = -1, init = "kmeanspp", tolerance = 1e-06, dist.type = "eucl") diff --git a/extras/knor_final.pdf b/extras/knor_final.pdf index a4f6954..2d83d13 100644 Binary files a/extras/knor_final.pdf and b/extras/knor_final.pdf differ diff --git a/extras/updated_benchmarks_may_1.csv b/extras/updated_benchmarks_may_1.csv deleted file mode 100644 index a872a56..0000000 --- a/extras/updated_benchmarks_may_1.csv +++ /dev/null @@ -1,10 +0,0 @@ -1 million sample (secs),100k sample (secs),10k sample (secs),1k sample (secs),package,language,process -282.7,15.27,0.7324,0.01682,Knor,R,full scan -854,87,6.11,0.000719,Sklearn KMeans,Python,full scan -11.2,1.41,0.000317,0.000141,Sklearn MiniBatch Kmeans,Python,stochastic -254.481,18.517,0.000794956,0.000031211,Mlpack ,C++ Wrapper,full scan -653.178,45.468,0.000824115,0.000017301,Clustering.jl,Julia,full scan -19.955,2.758,0.000166957,0.000009206,ParallelKMeans Lloyd,Julia,full scan -11.234,1.654,0.000109074,0.000012819,ParallelKMeans Hamerly,Julia,full scan -19.394,1.436,0.000109262,0.000013726,ParallelKMeans Elkan,Julia,full scan -14.08,0.000972914,0.000095325,0.000009802,ParallelKMeans YingYang,Julia,full scan \ No newline at end of file