如何解决R中群集程序包的轮廓函数中的下标超出范围
我试图找到聚类分析的平均轮廓宽度。我在R中的silhouette()
包中使用了cluster
函数。我收到“下标超出范围”错误。数据集的链接为here。我的代码是:
library(openxlsx)
library(cluster)
library(clustMixType)
dataset <- read.xlsx("./hepatitis.data.imputed.xlsx",na.strings = "")
# List type of variables
numeric_vars <- c("Age","Bilirubin","Sgot","Albumin")
categorical_vars <- names(dataset_imputed[-c(which(names(dataset_imputed)%in%numeric_vars))])
# Dataset for clustering (remove class label)
df <- dataset[-c(1)]
# distance matrix
Gower_dist <- as.matrix(daisy(df,metric = "gower"))
# k-prototype clustering
k_proto_clust <- kproto(data_fs,k = 2)
k_proto_clusters <- k_proto_clust$cluster
# Compute silhouette width
clustering_silhouette <- silhouette(x = k_proto_clusters,dmatrix = Gower_dist)
sum_clustering_silhouette <- summary(clustering_silhouette)
avg_silhouette_width_cluster <- sum_clustering_silhouette$avg.width
我仅需进行一次分析即可找到平均轮廓宽度,这没有任何问题。当我为优化模型调用avg_silhouette_width_cluster
时出现问题,该模型的平均轮廓宽度是针对具有不同数据子集的50个聚类分析计算的。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。