def calc_exact_neighbors(X, queries, n_queries, n_neighbors):
 print ('Building NearestNeighbors for %d samples in %d dimensions' % (X.shape[0], X.shape[1]))
 nbrs = NearestNeighbors(algorithm='brute', metric='cosine').fit(X)
 average_time = 0
 t0 = time()
 neighbors = nbrs.kneighbors(queries, n_neighbors=n_neighbors, return_distance=False)
 average_time = ((time() - t0) / n_queries)
 return (neighbors, average_time)

def calc_exact_neighbors ( X , queries , n_queries , n_neighbors ) : print ( 'Building NearestNeighbors for %d samples in %d dimensions' % ( X . shape [ 0 ] , X . shape [ 1 ] ) ) nbrs = NearestNeighbors ( algorithm = 'brute' , metric = 'cosine' ) . fit ( X ) average_time = 0 t0 = time ( ) neighbors = nbrs . kneighbors ( queries , n_neighbors = n_neighbors , return_distance = False ) average_time = ( ( time ( ) - t0 ) / n_queries ) return ( neighbors , average_time )
measures average times for exact neighbor queries .