Skip to content

Instantly share code, notes, and snippets.

@davideanastasia
Created February 2, 2019 12:30
Show Gist options
  • Save davideanastasia/e9dffe78348284132115a026dd3d4ee2 to your computer and use it in GitHub Desktop.
Save davideanastasia/e9dffe78348284132115a026dd3d4ee2 to your computer and use it in GitHub Desktop.
query_index = np.random.choice(taxi_data_pivot.shape[0])
distances, indexes = model_knn.kneighbors(
taxi_data_pivot.iloc[query_index, :].values.reshape(1, -1),
n_neighbors = 3)
taxis = [taxi_data_pivot.index[idx] for idx in indexes.flatten()]
for i in range(0, len(distances.flatten())):
print('{0}: {1}, with distance of {2}'.format(
i, taxi_data_pivot.index[indexes.flatten()[i]], distances.flatten()[i]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment