def fit(self,data,eps,MinPts): X = data n = X.shape[0] dist = computeEuclideanDistance(X)#distancematrix neighborhoods = [np.where(x<=eps)[0] for x in dist]#find all neighbourhoods within eps distance C = 0 D = data n = D.shape[0] visited = [False]* n # labels = [None]*n labels = -np.ones(n)#initialise labels to all -1 for index in range(0,n): if visited[index] == True: continue visited[index] = True NeighbourPts = self.regionQuery(index,eps,neighborhoods) if len(NeighbourPts) < MinPts: labels[index] = -1 else: C += 1 self.expandCluster(index,NeighbourPts,C,eps,MinPts,visited,labels,neighborhoods) return labels
def plotKnn(self,X,k): D = computeEuclideanDistance(X); sorted = np.sort(D) s = sorted[:,1:k] kDist = np.sort(np.mean(s[:,1:4],axis = 1)) objectId = np.arange(0,len(kDist)) plt.plot(objectId,kDist) plt.show()