python - Separating clusters by a line -
i have data set consists of several clusters. want separate these clusters line, voronoi diagram not created 1 dot. idea have determine shortest distance between each point , find points on outside of cluster. average distance needs taken, determine line separating clusters.
the closest point can determined via cdist. want loop on each cluster , compare each point in cluster other points in other clusters. however, i'm stuck @ doing this. below can find code written in python.
import matplotlib.pyplot plt scipy.spatial.distance import cdist def closest_point(pt, others): distances = cdist(pt, others) return others[distances.argmin()] ppx = [[615, 618, 621], [629, 623, 620, 625], [614, 622, 610, 612]] ppy = [[524, 530, 527], [559, 556, 548, 548], [559, 574, 572, 542]] in range(0,3): # range(len(grouped)) j in range(len(ppx[i])): = [[ppx[i][j], ppy[i][j]]] others = ..??.. print("closest:", closest_point(a, others)) plt.scatter(ppx[i],ppy[i]) plt.show()
as can see can can find 1 point in cluster (a), however, stuck when want put other 2 clusters in others. has idea how solve issue? or thinking in wrong direction?
i added picture 3 clusters , separation line intend make.
Comments
Post a Comment