-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathno_need_to_open.py
82 lines (67 loc) · 2.47 KB
/
no_need_to_open.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 15 20:53:50 2018
@author: abhi
"""
import kmeans_Knn as kk
import randomized_multiple_kdtreed as rmk
import common_function as cf
import pandas as pd
import numpy as np
import time
from sklearn.model_selection import train_test_split
import pickle
def multi_kdtree(data,y,test_data,test_y,no_of_trees = 5,no_of_dimensions = 600,variance = False,comparisions = 4) :
a = time.time()
multi_trees = rmk.randomized_trees(np.array(data),label = y,no_of_trees = no_of_trees,no_of_dimensions = no_of_dimensions,variance = variance,comparisions = comparisions )
multi_trees.make_data_sets()
multi_trees.make_tree()
accuracy = []
b = time.time()
tree_building_time = b-a
a = time.time()
#print(test_y)
for temp_x,temp_y in zip(test_data,test_y) :
#print(temp_x)
lst = [val[1] for val in multi_trees.get_nearest(temp_x)]
#print(lst)
if temp_y == max(set(lst), key=lst.count) :
accuracy.append(1)
else :
accuracy.append(0)
b = time.time()
prediction_time = b-a
return (sum(accuracy)/len(test_data))*100,tree_building_time,prediction_time
def kmeans_tree(data,y,test_data,test_y,k = 3,no_of_comparisions = 100,clustring_iteration = 7):
a =time.time()
loc_kk = kk.nary_tree(points,y,k,no_of_comparisions,clustring_iteration)
loc_kk.make_tree()
accuracy = []
b = time.time()
tree_building_time = b-a
a = time.time()
for temp_x,temp_y in zip(test_data,test_y) :
if temp_y == loc_kk.get_nearest(temp_x)[0][1][1]:
accuracy.append(1)
else :
accuracy.append(0)
b = time.time()
prediction_time = b-a
return (sum(accuracy)/len(test_data))*100,tree_building_time,prediction_time
def single_kdtree(data,y,test_data,test_y,cols,compare) :
a = time.time()
loc_rmk = rmk.knn_kdtree(data,y,cols,compare)
loc_rmk.make_tree()
accuracy = []
b = time.time()
tree_building_time = b-a
a = time.time()
for temp_x,temp_y in zip(test_data,test_y) :
if temp_y == loc_rmk.get_nearest(temp_x)[0][1]:
accuracy.append(1)
else :
accuracy.append(0)
b = time.time()
prediction_time = b-a
return (sum(accuracy)/len(test_data))*100,tree_building_time,prediction_time
if __name__ == "__main__" :