.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/annoy/plot_precision_script.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via JupyterLite or Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_annoy_plot_precision_script.py: Precision annoy.AnnoyIndex with examples ========================================== An example showing the :py:class:`~scikitplot.annoy.AnnoyIndex` class. .. GENERATED FROM PYTHON SOURCE LINES 12-28 .. code-block:: Python from __future__ import print_function import random; random.seed(0) import time # from annoy import AnnoyIndex # from scikitplot.annoy import AnnoyIndex from scikitplot.annoy import Index as AnnoyIndex try: from tqdm.auto import tqdm, trange except ImportError: # Fallback: dummy versions that ignore all args/kwargs tqdm = lambda iterable, *args, **kwargs: iterable trange = lambda n, *args, **kwargs: range(n) .. GENERATED FROM PYTHON SOURCE LINES 29-30 n, f = 1_000_000, 100 # 100~2.5GB .. GENERATED FROM PYTHON SOURCE LINES 30-50 .. code-block:: Python n, f = 100_000, 100 # 100~0.25GB 256~0.6GB idx = AnnoyIndex( f=f, metric='angular', ) idx.set_seed(0) for i in trange(n): if(i % (n//10) == 0): print(f"{i} / {n} = {1.0 * i / n}") # v = [] # for z in range(f): # v.append(random.gauss(0, 1)) v = [random.gauss(0, 1) for _ in range(f)] idx.add_item(i, v) idx.build(2 * f) idx.save('test.annoy') idx.info() .. rst-class:: sphx-glr-script-out .. code-block:: none /home/circleci/repo/galleries/examples/annoy/plot_precision_script.py:37: UserWarning: seed=0 resets to Annoy's default seed 0%| | 0/100000 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_precision_script.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_precision_script.zip ` .. include:: plot_precision_script.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_