-
-
Notifications
You must be signed in to change notification settings - Fork 26k
PERF Euclidean Specialization for ArgKminClassMode #28219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
PERF Euclidean Specialization for ArgKminClassMode #28219
Conversation
Thank you, @OmarManzoor. I do not have time to have a look into it at the moment. IIRC, there are two pathways for this case (extend Can you report benchmarks for various configurations against |
HI @jjerphan I did run some benchmarks. It seems that when we have test samples of about a 100 the performance has decreased. Otherwise for large test sizes the performance seems to have increased. Β· Running 2 total benchmarks (2 commits * 1 environments * 1 benchmarks)
[ 0.00%] Β· For scikit-learn commit 5d0219cf <argkmin_classmode_euclidean> (round 1/1):
[ 0.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[50.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[50.00%] Β·Β·Β· ========= ======== ============= ============ ============ ============= ============= ============ ============ ============ ============
-- n_features / n_neighbors
------------------ -----------------------------------------------------------------------------------------------------------------------
n_train n_test 50 / 100 50 / 500 50 / 1000 100 / 100 100 / 500 100 / 1000 500 / 100 500 / 500 500 / 1000
========= ======== ============= ============ ============ ============= ============= ============ ============ ============ ============
1000 100 2.24Β±0.2ms 4.12Β±0.3ms 3.42Β±0.3ms 2.27Β±0.2ms 4.38Β±0.3ms 3.76Β±0.4ms 4.02Β±0.5ms 6.25Β±1ms 5.89Β±0.7ms
1000 1000 4.13Β±0.02ms 11.7Β±1ms 9.06Β±0.1ms 4.72Β±0.01ms 13.1Β±0.09ms 12.8Β±0.1ms 13.4Β±0.2ms 19.9Β±0.2ms 19.8Β±0.2ms
1000 10000 32.9Β±4ms 65.0Β±4ms 69.2Β±5ms 33.6Β±3ms 70.5Β±3ms 70.3Β±3ms 73.7Β±4ms 105Β±3ms 118Β±6ms
10000 100 15.4Β±4ms 20.1Β±2ms 28.7Β±2ms 14.6Β±1ms 23.1Β±2ms 32.2Β±3ms 39.1Β±4ms 45.6Β±4ms 58.7Β±6ms
10000 1000 15.5Β±0.03ms 33.2Β±0.4ms 50.2Β±0.1ms 21.5Β±0.1ms 39.4Β±0.1ms 55.9Β±0.1ms 68.3Β±0.5ms 87.3Β±0.4ms 106Β±0.9ms
10000 10000 119Β±5ms 243Β±4ms 373Β±7ms 175Β±4ms 301Β±6ms 446Β±10ms 639Β±20ms 773Β±20ms 937Β±30ms
========= ======== ============= ============ ============ ============= ============= ============ ============ ============ ============
[50.00%] Β· For scikit-learn commit 8734d2f0 (round 1/1):
[50.00%] Β·Β· Building for conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0..
[50.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[100.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[100.00%] Β·Β·Β· ========= ======== ============= ============= ============= ============= ============= ============= ============= ============= ============
-- n_features / n_neighbors
------------------ ----------------------------------------------------------------------------------------------------------------------------
n_train n_test 50 / 100 50 / 500 50 / 1000 100 / 100 100 / 500 100 / 1000 500 / 100 500 / 500 500 / 1000
========= ======== ============= ============= ============= ============= ============= ============= ============= ============= ============
1000 100 1.60Β±0.01ms 3.62Β±0.06ms 5.61Β±0.09ms 1.66Β±0.01ms 3.70Β±0.05ms 5.70Β±0.09ms 2.22Β±0.02ms 4.33Β±0.07ms 6.39Β±0.1ms
1000 1000 10.8Β±0.2ms 27.6Β±9ms 39.9Β±0.5ms 11.0Β±0.1ms 26.9Β±0.6ms 40.4Β±0.4ms 16.1Β±0.2ms 32.1Β±0.5ms 45.8Β±0.6ms
1000 10000 42.8Β±1ms 152Β±4ms 290Β±7ms 48.5Β±2ms 156Β±3ms 297Β±8ms 88.7Β±2ms 197Β±6ms 324Β±5ms
10000 100 3.94Β±0.1ms 10.0Β±0.5ms 14.3Β±0.6ms 4.93Β±0.3ms 10.8Β±0.4ms 14.8Β±0.7ms 10.1Β±0.3ms 16.3Β±0.6ms 20.4Β±1ms
10000 1000 30.6Β±1ms 86.7Β±3ms 117Β±4ms 36.6Β±1ms 92.4Β±3ms 123Β±4ms 83.4Β±2ms 141Β±5ms 173Β±7ms
10000 10000 136Β±3ms 333Β±6ms 591Β±10ms 192Β±7ms 395Β±9ms 649Β±20ms 639Β±10ms 878Β±20ms 1.14Β±0.01s
========= ======== ============= ============= ============= ============= ============= ============= ============= ============= ============
| Change | Before [8734d2f0] | After [5d0219cf] <argkmin_classmode_euclidean> | Ratio | Benchmark (Parameter) |
|----------|----------------------|--------------------------------------------------|---------|----------------------------------------------------------------------------------------------|
| + | 3.94Β±0.1ms | 15.4Β±4ms | 3.89 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 50, 100) |
| + | 10.1Β±0.3ms | 39.1Β±4ms | 3.87 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 500, 100) |
| + | 4.93Β±0.3ms | 14.6Β±1ms | 2.95 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 100, 100) |
| + | 20.4Β±1ms | 58.7Β±6ms | 2.88 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 500, 1000) |
| + | 16.3Β±0.6ms | 45.6Β±4ms | 2.8 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 500, 500) |
| + | 14.8Β±0.7ms | 32.2Β±3ms | 2.18 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 100, 1000) |
| + | 10.8Β±0.4ms | 23.1Β±2ms | 2.13 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 100, 500) |
| + | 14.3Β±0.6ms | 28.7Β±2ms | 2.01 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 50, 1000) |
| + | 10.0Β±0.5ms | 20.1Β±2ms | 2.01 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 50, 500) |
| + | 2.22Β±0.02ms | 4.02Β±0.5ms | 1.81 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 500, 100) |
| + | 4.33Β±0.07ms | 6.25Β±1ms | 1.44 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 500, 500) |
| + | 1.60Β±0.01ms | 2.24Β±0.2ms | 1.4 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 50, 100) |
| + | 1.66Β±0.01ms | 2.27Β±0.2ms | 1.37 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 100, 100) |
| + | 3.70Β±0.05ms | 4.38Β±0.3ms | 1.18 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 100, 500) |
| + | 3.62Β±0.06ms | 4.12Β±0.3ms | 1.14 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 50, 500) |
| - | 136Β±3ms | 119Β±5ms | 0.88 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 50, 100) |
| - | 878Β±20ms | 773Β±20ms | 0.88 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 500, 500) |
| - | 16.1Β±0.2ms | 13.4Β±0.2ms | 0.84 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 500, 100) |
| - | 88.7Β±2ms | 73.7Β±4ms | 0.83 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 500, 100) |
| - | 83.4Β±2ms | 68.3Β±0.5ms | 0.82 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 500, 100) |
| - | 1.14Β±0.01s | 937Β±30ms | 0.82 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 500, 1000) |
| - | 42.8Β±1ms | 32.9Β±4ms | 0.77 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 50, 100) |
| - | 395Β±9ms | 301Β±6ms | 0.76 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 100, 500) |
| - | 333Β±6ms | 243Β±4ms | 0.73 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 50, 500) |
| - | 48.5Β±2ms | 33.6Β±3ms | 0.69 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 100, 100) |
| - | 649Β±20ms | 446Β±10ms | 0.69 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 100, 1000) |
| - | 5.70Β±0.09ms | 3.76Β±0.4ms | 0.66 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 100, 1000) |
| - | 591Β±10ms | 373Β±7ms | 0.63 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 50, 1000) |
| - | 32.1Β±0.5ms | 19.9Β±0.2ms | 0.62 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 500, 500) |
| - | 141Β±5ms | 87.3Β±0.4ms | 0.62 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 500, 500) |
| - | 5.61Β±0.09ms | 3.42Β±0.3ms | 0.61 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 100, 50, 1000) |
| - | 173Β±7ms | 106Β±0.9ms | 0.61 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 500, 1000) |
| - | 36.6Β±1ms | 21.5Β±0.1ms | 0.59 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 100, 100) |
| - | 197Β±6ms | 105Β±3ms | 0.54 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 500, 500) |
| - | 30.6Β±1ms | 15.5Β±0.03ms | 0.51 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 50, 100) |
| - | 26.9Β±0.6ms | 13.1Β±0.09ms | 0.49 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 100, 500) |
| - | 156Β±3ms | 70.5Β±3ms | 0.45 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 100, 500) |
| - | 123Β±4ms | 55.9Β±0.1ms | 0.45 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 100, 1000) |
| - | 11.0Β±0.1ms | 4.72Β±0.01ms | 0.43 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 100, 100) |
| - | 45.8Β±0.6ms | 19.8Β±0.2ms | 0.43 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 500, 1000) |
| - | 152Β±4ms | 65.0Β±4ms | 0.43 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 50, 500) |
| - | 92.4Β±3ms | 39.4Β±0.1ms | 0.43 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 100, 500) |
| - | 117Β±4ms | 50.2Β±0.1ms | 0.43 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 50, 1000) |
| - | 27.6Β±9ms | 11.7Β±1ms | 0.42 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 50, 500) |
| - | 10.8Β±0.2ms | 4.13Β±0.02ms | 0.38 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 50, 100) |
| - | 86.7Β±3ms | 33.2Β±0.4ms | 0.38 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 50, 500) |
| - | 324Β±5ms | 118Β±6ms | 0.36 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 500, 1000) |
| - | 40.4Β±0.4ms | 12.8Β±0.1ms | 0.32 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 100, 1000) |
| - | 297Β±8ms | 70.3Β±3ms | 0.24 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 100, 1000) |
| - | 290Β±7ms | 69.2Β±5ms | 0.24 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 10000, 50, 1000) |
| - | 39.9Β±0.5ms | 9.06Β±0.1ms | 0.23 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(1000, 1000, 50, 1000) |
SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE DECREASED.
|
Hi @OmarManzoor, thank you for the benchmarks! We might need to adapt the heuristic when Could you perform ASV benchmarks for
? Also, I believe that some part of this contribution might also be reused for |
Yes I think RadiusNeighbors will be similar but I think we will have to override the EuclideanSpecialization for that separately. |
So if I change the strategy to "auto" for "euclidean" the performance increases generically. Β· Running 2 total benchmarks (2 commits * 1 environments * 1 benchmarks)
[ 0.00%] Β· For scikit-learn commit d26bde4c <testing> (round 1/1):
[ 0.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[50.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[50.00%] Β·Β·Β· ========= ======== ============ ============ ============ ============
-- n_features / n_neighbors
------------------ ---------------------------------------------------
n_train n_test 50 / 100 50 / 1000 100 / 100 100 / 1000
========= ======== ============ ============ ============ ============
10000 100 3.64Β±0.1ms 10.2Β±0.3ms 4.14Β±0.1ms 11.1Β±0.5ms
10000 1000 29.7Β±2ms 89.9Β±2ms 34.5Β±2ms 102Β±8ms
10000 10000 116Β±5ms 387Β±20ms 187Β±10ms 437Β±20ms
========= ======== ============ ============ ============ ============
[50.00%] Β· For scikit-learn commit 8734d2f0 (round 1/1):
[50.00%] Β·Β· Building for conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0..
[50.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[100.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[100.00%] Β·Β·Β· ========= ======== ============ ============ ============ ============
-- n_features / n_neighbors
------------------ ---------------------------------------------------
n_train n_test 50 / 100 50 / 1000 100 / 100 100 / 1000
========= ======== ============ ============ ============ ============
10000 100 3.96Β±0.2ms 13.0Β±0.4ms 4.79Β±0.2ms 14.0Β±0.7ms
10000 1000 28.9Β±0.9ms 112Β±7ms 40.1Β±4ms 118Β±5ms
10000 10000 143Β±8ms 609Β±20ms 214Β±10ms 717Β±20ms
========= ======== ============ ============ ============ ============
| Change | Before [8734d2f0] | After [d26bde4c] <testing> | Ratio | Benchmark (Parameter) |
|----------|----------------------|------------------------------|---------|----------------------------------------------------------------------------------------------|
| - | 4.79Β±0.2ms | 4.14Β±0.1ms | 0.87 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 100, 100) |
| - | 214Β±10ms | 187Β±10ms | 0.87 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 100, 100) |
| - | 40.1Β±4ms | 34.5Β±2ms | 0.86 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 100, 100) |
| - | 118Β±5ms | 102Β±8ms | 0.86 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 100, 1000) |
| - | 143Β±8ms | 116Β±5ms | 0.81 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 50, 100) |
| - | 112Β±7ms | 89.9Β±2ms | 0.8 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 50, 1000) |
| - | 14.0Β±0.7ms | 11.1Β±0.5ms | 0.79 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 100, 1000) |
| - | 13.0Β±0.4ms | 10.2Β±0.3ms | 0.79 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 50, 1000) |
| - | 609Β±20ms | 387Β±20ms | 0.63 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 50, 1000) |
| - | 717Β±20ms | 437Β±20ms | 0.61 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 10000, 100, 1000) |
SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
However changing to "auto" doesn't work for the "manhattan" metric and the performance decreases Β· Running 2 total benchmarks (2 commits * 1 environments * 1 benchmarks)
[ 0.00%] Β· For scikit-learn commit d26bde4c <testing> (round 1/1):
[ 0.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[50.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[50.00%] Β·Β·Β· ========= ======== ============ ============ ============ ============
-- n_features / n_neighbors
------------------ ---------------------------------------------------
n_train n_test 50 / 100 50 / 1000 100 / 100 100 / 1000
========= ======== ============ ============ ============ ============
10000 100 7.59Β±0.2ms 13.5Β±0.4ms 14.3Β±0.7ms 20.3Β±0.3ms
10000 1000 71.0Β±2ms 126Β±5ms 135Β±5ms 208Β±9ms
10000 10000 487Β±10ms 847Β±60ms 1.15Β±0.04s 1.45Β±0.04s
========= ======== ============ ============ ============ ============
[50.00%] Β· For scikit-learn commit 8734d2f0 (round 1/1):
[50.00%] Β·Β· Building for conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0.
[50.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[100.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[100.00%] Β·Β·Β· ========= ======== ============ ============ ============ ============
-- n_features / n_neighbors
------------------ ---------------------------------------------------
n_train n_test 50 / 100 50 / 1000 100 / 100 100 / 1000
========= ======== ============ ============ ============ ============
10000 100 24.9Β±6ms 39.8Β±0.1ms 54.3Β±0.5ms 72.7Β±0.5ms
10000 1000 62.9Β±0.6ms 110Β±1ms 147Β±1ms 199Β±3ms
10000 10000 516Β±20ms 862Β±30ms 1.11Β±0.02s 1.54Β±0.06s
========= ======== ============ ============ ============ ============
| Change | Before [8734d2f0] | After [d26bde4c] <testing> | Ratio | Benchmark (Parameter) |
|----------|----------------------|------------------------------|---------|--------------------------------------------------------------------------------------------|
| + | 110Β±1ms | 126Β±5ms | 1.15 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 50, 1000) |
| + | 62.9Β±0.6ms | 71.0Β±2ms | 1.13 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 1000, 50, 100) |
| - | 39.8Β±0.1ms | 13.5Β±0.4ms | 0.34 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 50, 1000) |
| - | 24.9Β±6ms | 7.59Β±0.2ms | 0.3 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 50, 100) |
| - | 72.7Β±0.5ms | 20.3Β±0.3ms | 0.28 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 100, 1000) |
| - | 54.3Β±0.5ms | 14.3Β±0.7ms | 0.26 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(10000, 100, 100, 100) |
SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE DECREASED. Whereas if we keep the strategy as "parallel_on_X" the performance for "manhattan" does not degrade Β· Running 2 total benchmarks (2 commits * 1 environments * 1 benchmarks)
[ 0.00%] Β· For scikit-learn commit 5d0219cf <argkmin_classmode_euclidean> (round 1/1):
[ 0.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[50.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[50.00%] Β·Β·Β· ========= ======== ============= ============= ============ ============
-- n_features / n_neighbors
------------------ -----------------------------------------------------
n_train n_test 50 / 100 50 / 1000 100 / 100 100 / 1000
========= ======== ============= ============= ============ ============
10000 100 23.1Β±0.08ms 39.6Β±0.08ms 53.8Β±0.3ms 72.0Β±3ms
10000 1000 62.3Β±0.3ms 108Β±0.3ms 147Β±2ms 198Β±2ms
10000 10000 480Β±9ms 817Β±20ms 1.06Β±0.02s 1.38Β±0.01s
========= ======== ============= ============= ============ ============
[50.00%] Β· For scikit-learn commit 8734d2f0 (round 1/1):
[50.00%] Β·Β· Building for conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0..
[50.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[100.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[100.00%] Β·Β·Β· ========= ======== ============= ============= ============= ============
-- n_features / n_neighbors
------------------ ------------------------------------------------------
n_train n_test 50 / 100 50 / 1000 100 / 100 100 / 1000
========= ======== ============= ============= ============= ============
10000 100 23.1Β±0.09ms 39.6Β±0.08ms 53.9Β±0.09ms 72.0Β±0.1ms
10000 1000 62.2Β±0.3ms 108Β±0.4ms 146Β±0.4ms 197Β±0.2ms
10000 10000 497Β±10ms 819Β±10ms 1.04Β±0.02s 1.40Β±0.05s
========= ======== ============= ============= ============= ============
BENCHMARKS NOT SIGNIFICANTLY CHANGED. I think we need to adjust the strategy based on the metric used now that we are including the euclidean specialization. |
@jjerphan Here are the benchmarks that you requested. This is with "euclidean" and strategy "auto" Β· Running 2 total benchmarks (2 commits * 1 environments * 1 benchmarks)
[ 0.00%] Β· For scikit-learn commit d26bde4c <testing> (round 1/1):
[ 0.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[50.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[50.00%] Β·Β·Β· ========= ===================
-- n_test / n_features / n_neighbors
--------- -------------------
n_train 100000 / 100 / 10
========= ===================
10000 1.24Β±0.03s
========= ===================
[50.00%] Β· For scikit-learn commit 8734d2f0 (round 1/1):
[50.00%] Β·Β· Building for conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0..
[50.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[100.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[100.00%] Β·Β·Β· ========= ===================
-- n_test / n_features / n_neighbors
--------- -------------------
n_train 100000 / 100 / 10
========= ===================
10000 1.28Β±0.03s
========= ===================
BENCHMARKS NOT SIGNIFICANTLY CHANGED.
Β· Running 2 total benchmarks (2 commits * 1 environments * 1 benchmarks)
[ 0.00%] Β· For scikit-learn commit d26bde4c <testing> (round 1/1):
[ 0.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[50.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[50.00%] Β·Β·Β· ========= ====================
-- n_test / n_features / n_neighbors
--------- --------------------
n_train 1000000 / 100 / 10
========= ====================
1000 1.49Β±0.05s
========= ====================
[50.00%] Β· For scikit-learn commit 8734d2f0 (round 1/1):
[50.00%] Β·Β· Building for conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0..
[50.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[100.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[100.00%] Β·Β·Β· ========= ====================
-- n_test / n_features / n_neighbors
--------- --------------------
n_train 1000000 / 100 / 10
========= ====================
1000 1.64Β±0.02s
========= ====================
BENCHMARKS NOT SIGNIFICANTLY CHANGED.
Β· Running 2 total benchmarks (2 commits * 1 environments * 1 benchmarks)
[ 0.00%] Β· For scikit-learn commit d26bde4c <testing> (round 1/1):
[ 0.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[50.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[50.00%] Β·Β·Β· ========= ====================
-- n_test / n_features / n_neighbors
--------- --------------------
n_train 1000000 / 100 / 10
========= ====================
100 313Β±5ms
========= ====================
[50.00%] Β· For scikit-learn commit 8734d2f0 (round 1/1):
[50.00%] Β·Β· Building for conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0.
[50.00%] Β·Β· Benchmarking conda-py3.10-cython3.0.3-joblib1.3.2-numpy1.25.2-pandas2.1.0-scipy1.11.2-threadpoolctl3.2.0
[100.00%] Β·Β·Β· argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba ok
[100.00%] Β·Β·Β· ========= ====================
-- n_test / n_features / n_neighbors
--------- --------------------
n_train 1000000 / 100 / 10
========= ====================
100 456Β±9ms
========= ====================
| Change | Before [8734d2f0] | After [d26bde4c] <testing> | Ratio | Benchmark (Parameter) |
|----------|----------------------|------------------------------|---------|--------------------------------------------------------------------------------------------|
| - | 456Β±9ms | 313Β±5ms | 0.69 | argkmin_classmode.BruteForceKNeighborsClassifier.time_predict_proba(100, 1000000, 100, 10) |
SOME BENCHMARKS HAVE CHANGED SIGNIFICANTLY.
PERFORMANCE INCREASED.
|
Thank you. Can you provide the ASV benchmark script that you have used? |
Sure here is the code import numpy as np
from sklearn.neighbors import KNeighborsClassifier
from .common import Benchmark
N_SAMPLES_TRAIN = [10000]
N_SAMPLES_TEST = [100000]
N_FEATURES = [100]
N_NEIGHBORS = [10]
class BruteForceKNeighborsClassifier(Benchmark):
"""Benchmarks for KNeighborsClassifier.predict when using algorithm='brute'."""
param_names = ["n_train", "n_test", "n_features", "n_neighbors"]
params = (
N_SAMPLES_TRAIN,
N_SAMPLES_TEST,
N_FEATURES,
N_NEIGHBORS,
)
def setup(self, *params):
n_train, n_test, n_features, n_neighbors = params
metric = "euclidean"
self.knc = KNeighborsClassifier(
n_neighbors=n_neighbors, algorithm="brute", metric=metric
)
self.rng = np.random.RandomState(0)
self.X_train = self.rng.random_sample((n_train, n_features))
self.X_test = self.rng.random_sample((n_test, n_features))
self.y = self.rng.randint(low=0, high=2, size=(n_train,))
self.knc.fit(X=self.X_train, y=self.y)
def time_predict_proba(self, *params):
self.knc.predict_proba(self.X_test) |
I wonder whether it would make sense to add a heuristic for this specialization or if it would just add too much complexity. I think we need to socilitate others' opinions. |
@adam2392: would you be interested in reviewing this PR? |
I'm not 100% comfortable w/ the codebase around the tempitaing, but I can take a look as a beginner :). It'll also help me familiarize myself. I will revisit sometime this week. Just to summarize, is the following correct? Anything I missed?
|
Thats correct
Yeah that also seems correct. Basically Euclidean distances have their own specialisation already implemented for the ArgKmin and RadiusNeighbors classes. In the original PR to add ArgKminClassMode these specialisations were not included so as to avoid making the PR too complex and thus left for later. |
Reference Issues/PRs
Towards #25888
What does this implement/fix? Explain your changes.
Any other comments?
CC: @jjerphan @Micky774