Created
April 15, 2021 08:45
-
-
Save jjerphan/4bb326a67fcd944f2e01663383beaa5c to your computer and use it in GitHub Desktop.
Simple Benchmark for `sklearn.neighbours.BinaryTree`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.neighbors import KDTree, BallTree | |
from .common import Benchmark | |
class BinaryTreeStatsBenchmark(Benchmark): | |
""" | |
Base class for BinaryTree benchmarks for removing statistics. | |
""" | |
param_names = ['BinaryTree', 'n', 'd', 'leaf_size'] | |
params = ( | |
[KDTree, BallTree], | |
[100, 1000, 10000], | |
[10, 100, 1000], | |
[10, 100] | |
) | |
class BinaryTreeStatsCreation(BinaryTreeStatsBenchmark): | |
""" | |
Benchmarks for BinaryTree creation. | |
""" | |
def setup(self, BinaryTree, n, d, leaf_size): | |
self.samples = np.random.rand(n, d) | |
self.leaf_size = leaf_size | |
self.BinaryTree = BinaryTree | |
def time_creation(self, BinaryTree, n, d, leaf_size): | |
self.BinaryTree(self.samples, leaf_size=self.leaf_size) | |
class BinaryTreeStatsQuery(BinaryTreeStatsBenchmark): | |
""" | |
Benchmarks for BinaryTree queries. | |
""" | |
def setup(self, BinaryTree, n, d, leaf_size): | |
self.tree = BinaryTree(np.random.rand(n, d), leaf_size=leaf_size) | |
self.query_points = np.random.rand(n, d) | |
def time_query(self, BinaryTree, n, d, leaf_size): | |
self.tree.query( | |
self.query_points, | |
dualtree=False, | |
breadth_first=False, | |
sort_results=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Raw results for scikit-learn/scikit-learn#19893: