我已经检查了DBSCAN scikit问题(已经很老了,但是我的代码是给出错误:
[DBSCAN()得到一个意外的参数eps
输入的不是我的实际输入,只是测试值,但是我现在有这个问题。如果您能提供帮助,我将不胜感激
from sklearn.cluster import DBSCAN
import numpy as np
def clusterCenter(ll:list):
x=0
y=0
for el in ll:
x=x+el[0]
y=y+el[1]
x=x/len(ll)
y=y/len(ll)
return (x,y)
def printCoords(clist:list):
for el in clist:
x,y = el
print( str(x)+", "+str(y) )
def DBSCAN(X:np.array, max_distance:float, min_nodes_in_cluster:int):
clusterCenters=[]
dbscan = DBSCAN(eps=max_distance, min_samples=min_nodes_in_cluster,metric="euclidian").fit(X)
alllabels=dbscan.labels_
#getting the points in each cluster by using a dictionary
num=0
dict={}
for el in alllabels:
if dict.get(el) is None:
somearr=[]
somearr.append(X[num])
dict[el]=somearr
else:
dict[el].append(X[num])
num=num+1
#print all cluster centers for each cluster
for key in dict:
x,y=clusterCenter(dict[key])
clusterCenters.append((x,y))
return clusterCenters
X = np.array([[1, 2], [2, 2], [2, 3],[8, 7], [8, 8], [25, 80]])
cclist=DBSCAN(X,1.3,5)
printCoords(cclist)
问题是您将函数定义为DBSCAN
,它将覆盖从sklearn.cluster
导入的名称。只需将函数重命名为其他名称即可。