上海网络网站建设,国内搜索引擎排行榜,图木舒克市建设局网站,wap网页游戏网址概述
聚类算法大多数采用相似度来判断#xff0c;而相似度又大多数采用欧式距离长短来衡量#xff0c;而GMM采用了新的判断依据—–概率#xff0c;即通过属于某一类的概率大小来判断最终的归属类别 。 GMM的基本思想就是#xff1a;任意形状的概率分布都可以用多个高斯分…概述
聚类算法大多数采用相似度来判断而相似度又大多数采用欧式距离长短来衡量而GMM采用了新的判断依据—–概率即通过属于某一类的概率大小来判断最终的归属类别 。 GMM的基本思想就是任意形状的概率分布都可以用多个高斯分布函数去近似也就是GMM就是有多个单高斯密度分布组成的每一个Gaussian叫”Component”线性的加成在一起就组成了GMM概率密度。
算法函数
n_components 高斯模型的个数即聚类的目标个数 covariance_type : 通过EM算法估算参数时使用的协方差类型默认是”full” full每个模型使用自己的一般协方差矩阵 tied所用模型共享一个一般协方差矩阵 diag每个模型使用自己的对角线协方差矩阵 spherical每个模型使用自己的单一方差
可与K-means聚类比较
https://blog.csdn.net/fanzonghao/article/details/85045232
#coding:utf-8
import pandas as pd
from sklearn.cluster import KMeans
from sklearn.mixture import GaussianMixture
import time
import os
import numpy as np
import matplotlib.pyplot as plt
data_path ./Aggregation_cluster7.txt
# 导入数据
def load_data():points pd.read_table(data_path, headerNone)return pointsdef plotRes(data, clusterRes, clusterNum):结果可视化:param data:样本集:param clusterRes:聚类结果:param clusterNum: 类个数:return:nPoints len(data)scatterColors [black, blue, green, yellow, red, purple, orange, brown]for i in range(clusterNum):color scatterColors[i % len(scatterColors)]x1 []; y1 []for j in range(nPoints):if clusterRes[j] i:x1.append(data[j, 0])y1.append(data[j, 1])plt.scatter(x1, y1, ccolor, alpha1, marker)plt.show()
if __name__ __main__:n_cluster7pointsload_data()df pd.DataFrame(points, indexNone)X df.iloc[:, :-1].valuesprint(X)n X.shape[0]print( Do clustering )start_time time.time()gmm GaussianMixture(n_componentsn_cluster, covariance_typefull)# gmmKMeans(n_clustersn_cluster)gmm.fit(X)y_pred gmm.predict(X)end_time time.time()print(--- {} s ---.format(end_time - start_time))plotRes(X,y_pred,n_cluster)n_cluster3: n_cluster4: n_cluster5: n_cluster7: 由以上聚类图与kmeans比较可看出比kmeans效果好。