diff --git a/configs/experiments/dbscan_metrics.json b/configs/experiments/dbscan_metrics.json new file mode 100644 index 00000000..aeba8ea4 --- /dev/null +++ b/configs/experiments/dbscan_metrics.json @@ -0,0 +1,79 @@ +{ + "INCLUDE": ["../common/sklearn.json"], + "PARAMETERS_SETS": { + "dbscan metrics": { + "algorithm": { + "estimator": "DBSCAN", + "estimator_params": [ + { "metric": "euclidean" }, + { "metric": "manhattan" }, + { "metric": "chebyshev" }, + { "metric": "cosine" }, + { "metric": "minkowski", "p": 3 } + ] + } + }, + "dbscan eps and jobs": { + "algorithm": { + "estimator_params": { + "eps": "[SPECIAL_VALUE]distances_quantile:0.01", + "min_samples": 5, + "n_jobs": "[SPECIAL_VALUE]physical_cpus" + } + }, + "bench": { "n_runs": 5, "time_limit": 900 } + }, + "sklearn brute and tree": [ + { "algorithm": { "library": "sklearn", "device": "cpu", "estimator_params": { "algorithm": "brute" } } }, + { "algorithm": { "library": "sklearn", "device": "cpu", "estimator_params": { "algorithm": "auto" } } } + ], + "sklearnex cpu": { + "algorithm": { "library": "sklearnex", "device": "cpu", "estimator_params": { "algorithm": "brute" } } + }, + "sklearnex gpu": { + "algorithm": { + "library": "sklearnex", + "device": "gpu", + "estimator_params": { "algorithm": "brute" }, + "sklearn_context": { "array_api_dispatch": true } + }, + "data": { "format": "dpnp", "order": "C" } + }, + "dbscan datasets": { + "data": [ + { + "source": "make_blobs", + "generation_kwargs": [ + { "centers": 20, "n_samples": 50000, "n_features": 8, "cluster_std": 1.0 }, + { "centers": 20, "n_samples": 200000, "n_features": 8, "cluster_std": 1.0 }, + { "centers": 20, "n_samples": 100000, "n_features": 32, "cluster_std": 1.0 }, + { "centers": 20, "n_samples": 50000, "n_features": 256, "cluster_std": 1.0 }, + { "centers": 100, "n_samples": 500000, "n_features": 2, "cluster_std": 1.0 } + ], + "split_kwargs": { "ignore": true } + }, + { + "dataset": "cifar", + "split_kwargs": { "ignore": true }, + "preprocessing_kwargs": { "normalize": "mean" } + }, + { + "dataset": "covtype", + "split_kwargs": { "train_size": 100000, "test_size": null }, + "preprocessing_kwargs": { "normalize": "standard" } + } + ] + } + }, + "TEMPLATES": { + "sklearn dbscan": { + "SETS": ["sklearn brute and tree", "dbscan metrics", "dbscan eps and jobs", "dbscan datasets"] + }, + "sklearnex cpu dbscan": { + "SETS": ["sklearnex cpu", "dbscan metrics", "dbscan eps and jobs", "dbscan datasets"] + }, + "sklearnex gpu dbscan": { + "SETS": ["sklearnex gpu", "dbscan metrics", "dbscan eps and jobs", "dbscan datasets"] + } + } +} diff --git a/sklbench/benchmarks/sklearn_estimator.py b/sklbench/benchmarks/sklearn_estimator.py index 8c511ce3..dd9eb06a 100644 --- a/sklbench/benchmarks/sklearn_estimator.py +++ b/sklbench/benchmarks/sklearn_estimator.py @@ -225,7 +225,7 @@ def get_subset_metrics_of_estimator( ) } ) - if len(np.unique(y)) < 128: + if len(np.unique(y_compat)) < 128: metrics.update( { "homogeneity": ( diff --git a/sklbench/utils/special_params.py b/sklbench/utils/special_params.py index 80812012..2c5a994f 100644 --- a/sklbench/utils/special_params.py +++ b/sklbench/utils/special_params.py @@ -21,7 +21,7 @@ import numpy as np import pandas as pd from psutil import cpu_count -from sklearn.metrics import euclidean_distances +from sklearn.metrics import pairwise_distances from ..datasets import dataset_loading_functions from .bench_case import get_bench_case_value, set_bench_case_value @@ -288,7 +288,18 @@ def assign_case_special_values_on_run( # conversion to lower precision is required # to produce same distances quantile for different dtypes of x x_sample = x_sample.astype("float32") - dist = np.tril(euclidean_distances(x_sample, x_sample)).reshape(-1) + # the quantile is taken in the estimator's own metric, so eps has the right scale + metric = get_bench_case_value( + bench_case, "algorithm:estimator_params:metric", "euclidean" + ) + metric_kwargs = {} + if metric == "minkowski": + metric_kwargs["p"] = get_bench_case_value( + bench_case, "algorithm:estimator_params:p", 2 + ) + dist = np.tril( + pairwise_distances(x_sample, x_sample, metric=metric, **metric_kwargs) + ).reshape(-1) dist = dist[dist != 0] quantile = float(np.quantile(dist, quantile)) set_bench_case_value(bench_case, "algorithm:estimator_params:eps", quantile)