资源简介
指定半径下,使用meanshift算法原理对分布在二维平面上的多个点做密度聚类,求出每个聚类包含点的个数及中心坐标。
代码片段和文件信息
import numpy as np
import matplotlib.pyplot as plt
# X为数据集,每一条数据代表一个二维坐标
X = np.array([
[-4 -3.5] [-3.5 -5] [-2.7 -4.5]
[-2 -4.5] [-2.9 -2.9] [-0.4 -4.5]
[-1.4 -2.5] [-1.6 -2] [-1.5 -1.3]
[-0.5 -2.1] [-0.6 -1] [0 -1.6]
[-2.8 -1] [-2.4 -0.6] [-3.5 0]
[-0.2 4] [0.9 1.8] [1 2.2]
[1.1 2.8] [1.1 3.4] [1 4.5]
[1.8 0.3] [2.2 1.3] [2.9 0]
[2.7 1.2] [3 3] [3.4 2.8]
[3 5] [5.4 1.2] [6.3 2]
])
def mean_shift(data radius):
clusters = []
for i in range(len(data)):
cluster_centroid = data[i]
cluster_frequency = np.zeros(len(data))
while True:
temp_data = []
for j in range(len(data)):
v = data[j]
if np.linalg.norm(v
评论
共有 条评论