matlab silhouette函数,相当于Matlab的聚类质量函数?

本文介绍了如何在MATLAB和Python中实现聚类质量评估的silhouette函数,用于计算每个样本的轮廓系数。通过示例代码展示了如何计算并可视化这些值,以及如何在Python中利用scikit-learn库的silhouette_samples函数得到相同结果。
摘要由CSDN通过智能技术生成

我在下面展示了一个在MATLAB和Python/Numpy中的示例silhouette实现(请记住,我对MATLAB比较流利):

1) MATLAB语言function s = mySilhouette(X, IDX)

%# X : matrix of size N-by-p, data where rows are instances

%# IDX: vector of size N, cluster index of each instance (starting from 1)

%# s : vector of size N, silhouette score value of each instance

N = size(X,1); %# number of instances

K = numel(unique(IDX)); %# number of clusters

%# compute pairwise distance matrix

D = squareform( pdist(X,'euclidean').^2 );

%# indices belonging to each cluster

kIndices = accumarray(IDX, 1:N, [K 1], @(x){sort(x)});

%# compute a,b,s for each instance

%# a(i): average distance from i to all other data within the same cluster.

%# b(i): lowest average dist from i to the data of another single cluster

a = zeros(N,1);

b = zeros(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值