8000 [WIP] Draft: Precompute feature for PairwiseDistancesReductions by kyrajeep · Pull Request #29391 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Draft: Precompute feature for PairwiseDistancesReductions #29391

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sklearn/neighbors/tests/test_ball_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"manhattan": {},
"minkowski": dict(p=3),
"chebyshev": {},
"precomputed": {},
}

DISCRETE_METRICS = ["hamming", "canberra", "braycurtis"]
Expand All @@ -41,6 +42,9 @@

def brute_force_neighbors(X, Y, k, metric, **kwargs):
from sklearn.metrics import DistanceMetric

if metric == "precomputed":
return Y, np.argsort(Y, axis=1)[:, :k]

X, Y = check_array(X), check_array(Y)
D = DistanceMetric.get_metric(metric, **kwargs).pairwise(Y, X)
Expand Down Expand Up @@ -73,7 +77,8 @@ def test_ball_tree_query_metrics(metric, array_type, BallTreeImplementation):
dist1, ind1 = bt.query(Y, k)
dist2, ind2 = brute_force_neighbors(X, Y, k, metric)
assert_array_almost_equal(dist1, dist2)




@pytest.mark.parametrize(
"BallTreeImplementation, decimal_tol", zip(BALL_TREE_CLASSES, [6, 5])
Expand Down
Loading
0