Browse Source

stock similar

yufeng 4 years ago
parent
commit
0b7495a9fe
2 changed files with 43 additions and 0 deletions
  1. 23 0
      stock/find_similar.py
  2. 20 0
      stock/save_similar.py

+ 23 - 0
stock/find_similar.py

@@ -0,0 +1,23 @@
1
+from annoy import AnnoyIndex
2
+
3
+length = 20*4
4
+t = AnnoyIndex(length,metric="angular")
5
+t.load('stock.ann')
6
+
7
+stock_lines = []
8
+with open("/data/quantization/stock.log") as f:
9
+    for x in range(100):
10
+        stock_lines.append(eval(f.readline()))
11
+
12
+
13
+i = 0
14
+for stock in stock_lines:
15
+    v = []
16
+    for x in range(len(stock) - 1):
17
+        v.extend(stock[x]) 
18
+
19
+    index,distance = t.get_nns_by_item(i,5,include_distances=True)
20
+    print(index, distance)    
21
+
22
+    i = i + 1
23
+

+ 20 - 0
stock/save_similar.py

@@ -0,0 +1,20 @@
1
+from annoy import AnnoyIndex
2
+length = 20*4
3
+t = AnnoyIndex(length,metric="angular")
4
+
5
+stock_lines = []
6
+with open("/data/quantization/stock.log") as f:
7
+    for x in range(10000):
8
+        stock_lines.append(eval(f.readline()))
9
+
10
+
11
+i = 0
12
+for stock in stock_lines:
13
+    v = []
14
+    for x in range(len(stock) - 1):
15
+       v.extend(stock[x])
16
+    t.add_item(i, v)
17
+    i = i+1
18
+
19
+t.build(40) 
20
+t.save('stock.ann')