forked from HadXu/DeepLearningTutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest4.py
More file actions
57 lines (29 loc) · 624 Bytes
/
test4.py
File metadata and controls
57 lines (29 loc) · 624 Bytes
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
#!/usr/bin/python
#coding=utf-8
import string
datafile = open("car.txt")
n = 37
m = 2
mat = [[0]*m for i in range(n)]
i = 0
car = datafile.readline()
while car:
car_data = car.strip('\n').split(" ")
j = 0
for items in car_data:
#字符串转换成数字
data1 = string.atoi(items)
mat[i][j] = data1
j = j + 1
#print data1
i = i + 1
car = datafile.readline()
for i in range(n):
for j in range(m):
print mat[i][j],
print
from sklearn.cluster import KMeans
kmeans = KMeans(init='k-means++', n_clusters = 4, n_init = 10)
kmeans.fit(mat)
result = kmeans.predict(mat)
print result