K-means聚类算法:原理、实现与应用
1. K-means聚类算法实现
K-means聚类算法是一种常用的无监督学习算法,用于将数据点划分为指定数量的簇。以下是该算法的Python实现:
import math
import imp
import sys
import matplotlib.pyplot as plt
import matplotlib
import sys
sys.path.append('../common')
import common # noqa
matplotlib.style.use('ggplot')
# Returns k initial centroids for the given points.
def choose_init_centroids(points, k):
centroids = []
centroids.append(points[0])
while len(centroids) < k:
# Find the centroid that with the greatest possible distance
# to the closest already chosen centroid.
candidate = points[0]
candidate_dist = min_dist(points[0], centroids)
for point in points:
dist = min_dist(point, centroids)
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



