mysql cnique怎么设置_CLIQUE 聚类算法以及Java实现+多线程

CLIQUE(Clustering In QUEst)是一种简单的基于网格的聚类方法,用于发现子空间中基于密度的簇。CLIQUE把每个维划分成不重叠的区间,从而把数据对象的整个嵌入空间划分成单元。它使用一个密度阈值识别稠密单元和稀疏单元。一个单元是稠密的,如果映射到它的对象数超过该密度阈值。

CLIQUE识别候选搜索空间的主要策略是使用稠密单元关于维度的单调性。这基于频繁模式和关联规则挖掘使用的先验性质。在子空间聚类的背景下,单调性陈述如下:

一个k-维(>1)单元c至少有I个点,仅当c的每个(k-1)-维投影(它是(k-1)-维单元)至少有1个点。考虑下图,其中嵌人数据空间包含3个维:age,salary,vacation. 例如,子空间age和salary中的一个二维单元包含l个点,仅当该单元在每个维(即分别在age和salary上的投影都至少包含l个点).

100a91621014cad09e2e847f2fe9eaf3.png

CLIQUE通过两个阶段进行聚类。在第一阶段,CLIQUE把d-维数据空间划分若干互不重叠的矩形单元,并且从中识别出稠密单元。CLIQUE在所有的子空间中发现稠密单元。为了做到这一点,CLIQUE把每个维都划分成区间,并识别至少包含l个点的区间,其中l是密度阈值。然后,CLIQUE迭代地连接子空间.CLIQUE检查中的点数是否满足密度阈值。当没有候选产生或候选都不稠密时,迭代终止。

在第二阶段中,CLIQUE使用每个子空间中的稠密单元来装配可能具有任意形状的簇。其思想是利用最小描述长度(MDL)原理,使用最大区域来覆盖连接的稠密单元,其中最大区域是一个超矩形,落人该区域中的每个单元都是稠密的,并且该区域在该子空间的任何维上都不能再扩展。一般地找出簇的最佳描述是NP一困难的。因此,CLIQUE采用了一种简单的贪心方法。它从一个任意稠密单元开始,找出覆盖该单元的最大区域,然后在尚未被覆盖的剩余的稠密单元上继续这一过程。当所有稠密单元都被覆盖时,贪心方法终止。

最后给出Java实现(支持多属性聚类,多线程)

参考文章:《数据挖掘概念与技术》韩家炜

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是用鸢尾花数据做基于网格CLIQUE算法聚类算法的 Python 代码: ```python import numpy as np from sklearn import datasets # 鸢尾花数据集 iris = datasets.load_iris() X = iris.data y = iris.target # 网格CLIQUE算法 class GridCLIQUE(): def __init__(self, grid_size=0.5, density_threshold=5): self.grid_size = grid_size self.density_threshold = density_threshold def fit(self, X): n_samples, n_features = X.shape # 网格划分 grid_x = int(np.ceil((np.max(X[:, 0]) - np.min(X[:, 0])) / self.grid_size)) grid_y = int(np.ceil((np.max(X[:, 1]) - np.min(X[:, 1])) / self.grid_size)) grids = np.zeros((grid_x, grid_y), dtype=np.int) for i in range(n_samples): x, y = X[i, :2] x_idx = int(np.floor((x - np.min(X[:, 0])) / self.grid_size)) y_idx = int(np.floor((y - np.min(X[:, 1])) / self.grid_size)) grids[x_idx, y_idx] += 1 # 密度阈值 density = np.zeros((grid_x, grid_y), dtype=np.int) for i in range(grid_x): for j in range(grid_y): x_min = max(0, i - 1) x_max = min(grid_x - 1, i + 1) y_min = max(0, j - 1) y_max = min(grid_y - 1, j + 1) neighbor_grids = grids[x_min:x_max+1, y_min:y_max+1] density[i, j] = np.sum(neighbor_grids) - grids[i, j] threshold = np.percentile(density, 100 - self.density_threshold) # 核心网格单元 core_grids = np.argwhere(density >= threshold) n_core_grids = core_grids.shape[0] core_labels = np.zeros(n_core_grids, dtype=np.int) for i in range(n_core_grids): x, y = core_grids[i] if core_labels[i] == 0: core_labels[i] = i + 1 x_min = max(0, x - 1) x_max = min(grid_x - 1, x + 1) y_min = max(0, y - 1) y_max = min(grid_y - 1, y + 1) neighbor_grids = grids[x_min:x_max+1, y_min:y_max+1] neighbor_density = density[x_min:x_max+1, y_min:y_max+1] for j in range(n_core_grids): if i != j and core_labels[j] == 0: x2, y2 = core_grids[j] if x_min <= x2 <= x_max and y_min <= y2 <= y_max: if neighbor_density[x2-x_min, y2-y_min] >= threshold: core_labels[j] = core_labels[i] # 簇合并 cluster_labels = np.zeros((grid_x, grid_y), dtype=np.int) for i in range(n_core_grids): x, y = core_grids[i] label = core_labels[i] if cluster_labels[x, y] == 0: cluster_labels[x, y] = label x_min = max(0, x - 1) x_max = min(grid_x - 1, x + 1) y_min = max(0, y - 1) y_max = min(grid_y - 1, y + 1) neighbor_labels = cluster_labels[x_min:x_max+1, y_min:y_max+1] for j in range(n_core_grids): if i != j and core_labels[j] == label: x2, y2 = core_grids[j] if x_min <= x2 <= x_max and y_min <= y2 <= y_max: neighbor_labels[core_grids[j, 0]-x_min, core_grids[j, 1]-y_min] = label # 分配剩余网格单元 for i in range(grid_x): for j in range(grid_y): if cluster_labels[i, j] == 0: x_min = max(0, i - 1) x_max = min(grid_x - 1, i + 1) y_min = max(0, j - 1) y_max = min(grid_y - 1, j + 1) neighbor_labels = cluster_labels[x_min:x_max+1, y_min:y_max+1] unique_labels = np.unique(neighbor_labels) if unique_labels.shape[0] == 1: cluster_labels[i, j] = unique_labels[0] else: cluster_labels[i, j] = unique_labels[np.argmax(np.bincount(neighbor_labels.flatten()))] self.labels_ = cluster_labels.reshape(-1) return self # 聚类 grid_clique = GridCLIQUE(grid_size=0.5, density_threshold=5) labels = grid_clique.fit(X[:, :2]).labels_ # 可视化 import matplotlib.pyplot as plt plt.scatter(X[:, 0], X[:, 1], c=labels) plt.xlabel('Sepal length') plt.ylabel('Sepal width') plt.show() ``` 其中,`GridCLIQUE` 类实现了网格CLIQUE算法,`grid_size` 和 `density_threshold` 分别为网格大小和密度阈值,`fit` 方法用于聚类。 代码中只用了鸢尾花数据的前两个特征(即花萼长度和花萼宽度),并将聚类结果可视化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值