-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpwards.py
31 lines (30 loc) · 853 Bytes
/
pwards.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
from sklearn.cluster import AgglomerativeClustering
import numpy as np
from numpy.random import *
import time
from datetime import datetime
from numpy import *
#X = rand(1797, 64)
def read_file(file_name):
with open(file_name) as f:
content = f.readline()
content = content.split(' ')
n = int(content[0])
d = int(content[1])
#k = int(content[2])
X = zeros((n, d))
for i in range(n):
content = f.readline()
content = content.split(' ')
for j in range(d):
X[i, j] = float(content[j])
return X
#X = rand(15000, 2)
X = read_file("./news_1000.in")
print (X.shape)
n_clusters = 1
ward = AgglomerativeClustering(n_clusters=n_clusters, linkage='ward', connectivity=None)
start = time.time()
ward.fit(X)
end = time.time()
print(end - start)