MATLAB聚类有效性评价指标(外部)

作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/

更多内容,请看:MATLAB聚类MATLAB聚类有效性评价指标(外部 成对度量)MATLAB: Clustering Algorithms

前提:数据的真实标签已知!

1. 归一化互信息(Normalized Mutual information)

定义

程序

function MIhat = nmi(A, B)
%NMI Normalized mutual information
% A, B: 1*N;
if length(A) ~= length(B)
error('length( A ) must == length( B)');
end
N = length(A);
A_id = unique(A);
K_A = length(A_id);
B_id = unique(B);
K_B = length(B_id);
% Mutual information
A_occur = double (repmat( A, K_A, 1) == repmat( A_id', 1, N ));
B_occur = double (repmat( B, K_B, 1) == repmat( B_id', 1, N ));
AB_occur = A_occur * B_occur';
P_A= sum(A_occur') / N;
P_B = sum(B_occur') / N;
P_AB = AB_occur / N;
MImatrix = P_AB .* log(P_AB ./(P_A' * P_B)+eps);
MI = sum(MImatrix(:));
% Entropies
H_A = -sum(P_A .* log(P_A + eps),2);
H_B= -sum(P_B .* log(P_B + eps),2);
%Normalized Mutual information
MIhat = MI / sqrt(H_A*H_B); 

结果

>> A = [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3];
>> B = [1 2 1 1 1 1 1 2 2 2 2 3 1 1 3 3 3];
>> MIhat = nmi(A, B) MIhat = 0.3646

2. Rand统计量(Rand index)

定义

程序

function [AR,RI,MI,HI]=RandIndex(c1,c2)
%RANDINDEX - calculates Rand Indices to compare two partitions
% ARI=RANDINDEX(c1,c2), where c1,c2 are vectors listing the
% class membership, returns the "Hubert & Arabie adjusted Rand index".
% [AR,RI,MI,HI]=RANDINDEX(c1,c2) returns the adjusted Rand index,
% the unadjusted Rand index, "Mirkin's" index and "Hubert's" index. if nargin < 2 || min(size(c1)) > 1 || min(size(c2)) > 1
error('RandIndex: Requires two vector arguments')
return
end C=Contingency(c1,c2); %form contingency matrix n=sum(sum(C));
nis=sum(sum(C,2).^2); %sum of squares of sums of rows
njs=sum(sum(C,1).^2); %sum of squares of sums of columns t1=nchoosek(n,2); %total number of pairs of entities
t2=sum(sum(C.^2)); %sum over rows & columnns of nij^2
t3=.5*(nis+njs); %Expected index (for adjustment)
nc=(n*(n^2+1)-(n+1)*nis-(n+1)*njs+2*(nis*njs)/n)/(2*(n-1)); A=t1+t2-t3; %no. agreements
D= -t2+t3; %no. disagreements if t1==nc
AR=0; %avoid division by zero; if k=1, define Rand = 0
else
AR=(A-nc)/(t1-nc); %adjusted Rand - Hubert & Arabie 1985
end RI=A/t1; %Rand 1971 %Probability of agreement
MI=D/t1; %Mirkin 1970 %p(disagreement)
HI=(A-D)/t1; %Hubert 1977 %p(agree)-p(disagree) function Cont=Contingency(Mem1,Mem2) if nargin < 2 || min(size(Mem1)) > 1 || min(size(Mem2)) > 1
error('Contingency: Requires two vector arguments')
return
end Cont=zeros(max(Mem1),max(Mem2)); for i = 1:length(Mem1)
Cont(Mem1(i),Mem2(i))=Cont(Mem1(i),Mem2(i))+1;
end

程序中包含了四种聚类度量方法:Adjusted Rand index、Rand index、Mirkin index、Hubert index。

结果

>> A = [1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3];
>> B = [1 2 1 1 1 1 1 2 2 2 2 3 1 1 3 3 3];
>> [AR,RI,MI,HI]=RandIndex(A,B) AR = 0.2429 RI = 0.6765 MI = 0.3235 HI = 0.3529

3. 参考文献

(simple) Tool for estimating the number of clusters

Mutual information and Normalized Mutual information 互信息和标准化互信息

Evaluation of clustering

MATLAB聚类有效性评价指标(外部)的更多相关文章

  1. MATLAB聚类有效性评价指标(外部 成对度量)

    MATLAB聚类有效性评价指标(外部 成对度量) 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 更多内容,请看:MATLAB: Clustering ...

  2. matlab 聚类

    目前已知matlab的聚类方法有三种: 一.利用 clusterdata函数对样本数据进行一次聚类,其缺点为可供用户选择的面较窄,不能更改距离的计算方法: 二.层次聚类,该方法较为灵活,需要进行细节了 ...

  3. 各类聚类(clustering)算法初探

    1. 聚类简介 0x1:聚类是什么? 聚类是一种运用广泛的探索性数据分析技术,人们对数据产生的第一直觉往往是通过对数据进行有意义的分组.很自然,首先要弄清楚聚类是什么? 直观上讲,聚类是将对象进行分组 ...

  4. 聚类算法与K-means实现

    聚类算法与K-means实现 一.聚类算法的数学描述: 区别于监督学习的算法(回归,分类,预测等),无监督学习就是指训练样本的 label 未知,只能通过对无标记的训练样本的学习来揭示数据的内在规律和 ...

  5. 【分享】Matlab R2015a 发布啦!

    本博客所有文章分类的总目录:http://www.cnblogs.com/asxinyu/p/4288836.html Matlab和C#混合编程文章目录:http://www.cnblogs.com ...

  6. Matlab聚类分析[转]

    Matlab聚类分析[转] Matlab提供系列函数用于聚类分析,归纳起来具体方法有如下: 方法一:直接聚类,利用clusterdata函数对样本数据进行一次聚类,其缺点为可供用户选择的面较窄,不能更 ...

  7. 聚类 高维聚类 聚类评估标准 EM模型聚类

    高维数据的聚类分析 高维聚类研究方向 高维数据聚类的难点在于: 1.适用于普通集合的聚类算法,在高维数据集合中效率极低 2.由于高维空间的稀疏性以及最近邻特性,高维的空间中基本不存在数据簇. 在高维聚 ...

  8. 信号与系统实验序章0——MATLAB基础命令入门

    本次开启新的系列,关于用Matlab实现常见信号和函数的生成和变换. 同时如果没有MATLAB基础,那么可以跟着本文一步一步学习Matlab的相关操作,本文旨在记录在信号与系统课程中MATLAB的学习 ...

  9. 2019-07-28【机器学习】无监督学习之聚类 DBSCAN方法及其应用 (在线大学生上网时间分析)

    样本: import numpy as np import sklearn.cluster as skc from sklearn import metrics import matplotlib.p ...

随机推荐

  1. kibana的query string syntax 笔记

    kibana的query string syntax 并不是 Query String Query,只能说类似.kibana的 Lucene query string syntax(es的query ...

  2. SpringCloud找不到@HystrixCommand标签

    版本声明: SpringCloud:Greenwich.SR4 SpringBoot:2.1.9.RELEASE 解决方案: 添加坐标 <dependency> <groupId&g ...

  3. Prometheus学习系列(九)之Prometheus 存储

    前言 本文来自Prometheus官网手册 和 Prometheus简介 存储 Prometheus是一个本地磁盘时间序列数据库,但也可选择与远程存储系统集成,其本地时间序列数据库以自定义格式在磁盘上 ...

  4. 《Dotnet9》系列之建站-Dotnet9建站20天感悟

    本人站点 https://dotnet9.com,建站20天了,在这给站长朋友讲述个人建站经历,希望对大家能有所帮助. https://dotnet9.com 网站采用 宝塔 + WordPress ...

  5. springboot~yml里的自定义配置~续

    之前写了关于读取自定义配置的文章springboot~yml里的自定义配置,而今天主要说一下对复杂配置信息的读取方法,我们简单的配置用@Value注解就可以了,而结构复杂的一般使用@Configura ...

  6. Filter Lookup Editor Data Source 筛选器查找编辑器数据源

    In this lesson, you will learn how to filter the data displayed by a lookup editor. This editor is s ...

  7. Tomcat乱码或异常

    一.控制台乱码 原因:Tomcat与Windows编码不一致导致 解决办法:首先找到conf/logging.properties文件,然后打开后找到“java.util.logging.Consol ...

  8. shell 脚本里的$(( ))、$( )、``与${ }的区别

    shell  脚本里的命令执行 1. 在bash中,$( )与` `(反引号)都是用来作命令替换的. 命令替换与变量替换差不多,都是用来重组命令行的,先完成引号里的命令行,然后将其结果替换出来,再重组 ...

  9. Appium(一):java环境、AndroidSDK环境

    1. java环境 java的下载和安装可以看我以前写的Java基础:<java下载和安装>. 2. AndroidSDK环境 2.1 AndroidSDK下载 我们进入:https:// ...

  10. python 实现 PC 客户端自动化快速入门:pywinauto !

    本文转载自:http://www.lemfix.com/topics/420 一.前言 ​ 我们柠檬班的小可爱,在学完我们柠檬班自动化的课程之后,就掌握了接口自动化,web自动化,app自动化,这些工 ...