-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbico.py
45 lines (28 loc) · 1.13 KB
/
bico.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
from cf_tree import CFTree
from clustering_feature import ClusteringFeature
from geo.point import Point
from streaming_clustering_model import StreamingClusteringModel
class BICO(StreamingClusteringModel):
def __init__(self,kmeans_model,max_nodes=10,dim=2,thresh=0.001):
# self.max_nodes=max_nodes
# self.dim=dim
# self.thresh=thresh
self.model=kmeans_model
self.cf_tree=CFTree(dim=dim,thresh=thresh,max_nodes= max_nodes)
def partial_fit(self,X): # the online operation in streaming configuration
self.cf_tree.bulk_insert(X)
return self
def fit(self,X): # the offline operation in streaming configuration
self.cf_tree.bulk_insert(X)
coreset_centers,weights=self.cf_tree.get_coreset()
self.model.fit(coreset_centers,sample_weight=weights)
return self
def transform(self,X): # transform from cluster to distance space
dist=self.model.transform(X)
return dist
def score(self,X):
s=self.model.score(X)
return s
def predict(self,X):
y= self.model.predict(X)
return y