简体   繁体   中英

DBSCAN scikit python eps unexpected

I checked the DBSCAN scikit questions (which are very old) already but my code is giving an error:

DBSCAN() got an unexpected argument eps

The input is not my actual input just test values but I have this problem now. I would be grateful if you can help

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)

The problem is that you define your function as DBSCAN , which overrides the name that is imported from sklearn.cluster . Just rename your function to something else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM