kmeans.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:clustering_od 作者: faical-allou 项目源码 文件源码
def calculateCentroid(self):
        if len(self.points) > 0 :
            # Finds a virtual center point for a group of n-dimensional points
            numPoints = len(self.points)
            # Get a list of all coordinates in this cluster
            coords = [p.coords for p in self.points]
            print('cluster has: '+ str(numPoints) + ' point')
            # Reformat that so all x's are together, all y'z etc.
            unzipped = zip(*coords)
            # Calculate the mean for each dimension
            centroid_coords = [math.fsum(dList)/numPoints for dList in unzipped]
            return Point(centroid_coords,'Centroid')
        else:
            return self.centroid
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号