R语言 ConsensusClusterPlus 确定最佳K值

用PCA的方法确定最佳聚类数
M 为计算出共识矩阵
Fn = ecdf(M[lower.tri(M)]) 提取出共识矩阵下三角的数据,然后将用ecdf 方法生成拟合曲线
计算0.1到0.9之间的面积
面积最小值对应K为最佳K

Kvec = 2:maxK
x1 = 0.1; x2 = 0.9 # threshold defining the intermediate sub-interval
PAC = rep(NA,length(Kvec))
names(PAC) = paste("K=",Kvec,sep="") # from 2 to maxK
for(i in Kvec){
M = results[[i]]$consensusMatrix
Fn = ecdf(M[lower.tri(M)])
PAC[i-1] = Fn(x2) - Fn(x1)}#end for i# The optimal K
optK = Kvec[which.min(PAC)]

猜你喜欢

转载自blog.csdn.net/YJJ18636810884/article/details/83242090