【发布时间】:2016-10-21 09:23:06
【问题描述】:
举个例子
X: 1 2 3 4 5
Y: .9 .91 .92 .93 .94
Z: 20 36 999 211
M. 4000 3456 1 0
当我有这样的数据集时,选择哪种聚类算法?另外,如何解释聚类后的结果? 含义:如何将 4D 数据集馈送到集群中。
我发现 DBSCAN 可以在互联网上获得 2D 的情节是可能的。由于我的数据集是 4D 并且不合逻辑地变化...我不敢将其提供给算法
`
import pdb
import matplotlib.pyplot as plt
from numpy.random import rand
from numpy import square, sqrt
def regionQuery(P, eps, D):
neighbourPts = []
for point in D:
#print point
if sqrt(square(P[1] - point[1]) + square(P[2] - point[2]))<eps:
neighbourPts.append(point)
return neighbourPts
def DBSCAN(D, eps, MinPts):
noise = []
visited = []
C = []
c_n = -1
for point in D:
visited.append(point) #marking point as visited
# print point
neighbourPts = regionQuery(point, eps, D)
if len(neighbourPts) < MinPts:
noise.append(point)
else:
C.append([])
c_n+=1
expandCluster(point, neighbourPts, C, c_n,eps, MinPts, D, visited)
print("no. of clusters: " , len(C) )
print("length of noise:", len(noise))
for cluster in C:
col =[rand(1),rand(1),rand(1)]
#print(cluster)
plt.scatter([i[1] for i in cluster],[i[2] for i in cluster],color=col)
plt.show()
def expandCluster(P, neighbourPts, C, c_n,eps, MinPts, D, visited):
C[c_n].append(P)
for point in neighbourPts:
if point not in visited:
visited.append(point)
neighbourPts_2 = regionQuery(point, eps, D)
if len(neighbourPts_2) >= MinPts:
neighbourPts += neighbourPts_2
if point not in (i for i in C):
C[c_n].append(point)
eps =20#input("enter eps")
x=200*rand(10)
y=200*rand(10)
l=[]
for i in range(10):
l.append([i,x[i],y[i]])
#pdb.set_trace()
DBSCAN(l,eps,1)`
【问题讨论】:
-
您使用哪种语言?
标签: python machine-learning cluster-analysis dbscan