def calc_accuracy(X, queries, n_queries, n_neighbors, exact_neighbors, average_time_exact, **lshf_params):
 print ('Building LSHForest for %d samples in %d dimensions' % (X.shape[0], X.shape[1]))
 lshf = LSHForest(**lshf_params)
 t0 = time()
 lshf.fit(X)
 lshf_build_time = (time() - t0)
 print ('Done in %0.3fs' % lshf_build_time)
 accuracy = 0
 t0 = time()
 approx_neighbors = lshf.kneighbors(queries, n_neighbors=n_neighbors, return_distance=False)
 average_time_approx = ((time() - t0) / n_queries)
 for i in range(len(queries)):
  accuracy += np.in1d(approx_neighbors[i], exact_neighbors[i]).mean()
 accuracy /= n_queries
 speed_up = (average_time_exact / average_time_approx)
 print ('Average time for lshf neighbor queries: %0.3fs' % average_time_approx)
 print ('Average time for exact neighbor queries: %0.3fs' % average_time_exact)
 print ('Average Accuracy : %0.2f' % accuracy)
 print ('Speed up: %0.1fx' % speed_up)
 return (speed_up, accuracy)

def calc_accuracy ( X , queries , n_queries , n_neighbors , exact_neighbors , average_time_exact , ** lshf_params ) : print ( 'Building LSHForest for %d samples in %d dimensions' % ( X . shape [ 0 ] , X . shape [ 1 ] ) ) lshf = LSHForest ( ** lshf_params ) t0 = time ( ) lshf . fit ( X ) lshf_build_time = ( time ( ) - t0 ) print ( 'Done in %0.3fs' % lshf_build_time ) accuracy = 0 t0 = time ( ) approx_neighbors = lshf . kneighbors ( queries , n_neighbors = n_neighbors , return_distance = False ) average_time_approx = ( ( time ( ) - t0 ) / n_queries ) for i in range ( len ( queries ) ) : accuracy += np . in1d ( approx_neighbors [ i ] , exact_neighbors [ i ] ) . mean ( ) accuracy /= n_queries speed_up = ( average_time_exact / average_time_approx ) print ( 'Average time for lshf neighbor queries: %0.3fs' % average_time_approx ) print ( 'Average time for exact neighbor queries: %0.3fs' % average_time_exact ) print ( 'Average Accuracy : %0.2f' % accuracy ) print ( 'Speed up: %0.1fx' % speed_up ) return ( speed_up , accuracy )
calculates accuracy and the speed up of lshforest .