annoy with examples#

An example showing the annoy function.

8 # Authors: Spotify AB
9 # SPDX-License-Identifier: Apache-2.0

from annoy import AnnoyIndex

13 from scikitplot.cexternals.annoy import AnnoyIndex
16 a = AnnoyIndex(3, 'angular')
17 a.add_item(0, [1, 0, 0])
18 a.add_item(1, [0, 1, 0])
19 a.add_item(2, [0, 0, 1])
20 a.build(-1)
21 a.save('test.tree')
True
24 b = AnnoyIndex(3, 'angular')
25 b.load('test.tree')
True
28 print(b.get_nns_by_item(0, 100))
29 print(b.get_nns_by_vector([1.0, 0.5, 0.5], 100))
[0, 1, 2]
[0, 1, 2]

Tags: model-type: classification model-workflow: impute plot-type: bar level: beginner purpose: showcase

Total running time of the script: (0 minutes 0.116 seconds)

Related examples

annoy with examples

annoy with examples

annoy with examples

annoy with examples

Visualkeras: Spam Classification Conv1D Dense Example

Visualkeras: Spam Classification Conv1D Dense Example

plot_silhouette with examples

plot_silhouette with examples

Gallery generated by Sphinx-Gallery