项目文件夹

文件
Elías Snorrason 71ba4b3209 Add a knn module (#1117)
Co-authored-by: Jonas Mueller <1390638+jwmueller@users.noreply.github.com>
2024-05-14 13:59:15 -04:00

32 行
976 B
Python

import numpy as np
import pytest
from cleanlab.internal.neighbor.metric import decide_default_metric
@pytest.mark.parametrize(
"N",
[2, 10, 50, 100, 101],
)
def test_decide_default_metric_for_2d_and_3d_features(N):
# 2D and 3D features should always use the euclidean metric, disregarding the different implementations.
for M in [2, 3]:
X = np.random.rand(N, M)
metric = decide_default_metric(X)
if hasattr(metric, "__name__"):
error_msg = "The metric should be the string 'euclidean' for N > 100."
assert N <= 100, error_msg
metric = getattr(metric, "__name__")
assert metric == "euclidean"
@pytest.mark.parametrize(
"M",
[4, 5, 10, 50, 100],
)
def test_decide_default_metric_for_high_dimensional_features(M):
# High-dimensional features should always use the cosine metric.
X = np.random.rand(100, M)
metric = decide_default_metric(X)
assert metric == "cosine"