-
Notifications
You must be signed in to change notification settings - Fork 0
/
2a_script_fuzzy(1).R
84 lines (58 loc) · 2.01 KB
/
2a_script_fuzzy(1).R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
library(cluster)
library(factoextra)
rm(list=ls())
setwd("C:/Users/vince/Desktop/Tesi/SC-V15") #modifica
load("distMatrixDoc2Vec.RData")
K <- 2
rnames <- row.names(distMatrix)
fcluster <- fanny(distMatrix, k = K , maxit = 1000, diss = TRUE, memb.exp = 1.01, keep.diss = TRUE,
tol = 1e-20)
save(fcluster, file="fuzzy.RData")
# plot
#clusplot(distMatrix, fcluster$clustering, color=T, shade=T, labels=4, lines=0)
Patient_Status<-read.table("Patient_Status.csv",
header = TRUE,
sep = ";",
stringsAsFactors = FALSE,
fileEncoding = "UTF-8-BOM")
patstatus <- Patient_Status$RECRUITMENT_CAT
patstatus[which(patstatus == "PD")] <- "PD"
patstatus[which(patstatus == "PRODROMA")] <- "PD"
patstatus[which(patstatus == "GENPD")] <- "PD"
patstatus[which(patstatus == "REGPD")] <- "PD"
patstatus[which(patstatus == "GENUN")] <- "GENUN"
patstatus[which(patstatus == "HC")] <- "GENUN"
patstatus[which(patstatus == "REGUN")] <- "GENUN"
patstatus <- as.data.frame(patstatus)
patno <- Patient_Status$PATNO
spatno <- paste(as.character(patno),".txt",sep="")
row.names(patstatus) <- spatno
spatno <- as.data.frame(spatno)
th <- 1/K;
cls <- vector("list",K)
for(i in 1:K)
{
cat("Cluster all:",i,length(fcluster$membership[,i]),"\n", sep=" ")
cls[[i]] <- as.vector(which(fcluster$membership[,i] > th))
}
cat("\n")
varcls <- vector("list",K)
for(i in 1:K)
{
cat("Cluster:",i,"number of elements",length(cls[[i]]),"\n", sep=" ")
#print(rnames[cls[[i]]])
varcls[[i]] <- patstatus[which(row.names(patstatus) %in% rnames[cls[[i]]]),1]
print(table(varcls[[i]]))
cat("\n")
}
#
# cluster <- fcluster$membership
# cluster <- as.data.frame(cluster)
# save(cluster, file="cluster_fuzzy.RData")
# cluster1 <- rnames[cls[[1]]]
# save(cluster1, file="cluster1_fuzzy.RData")
#
# cluster2 <- rnames[cls[[2]]]
# save(cluster2, file="cluster2_fuzzy.RData")
#
#fviz_silhouette(fcluster, palette = "rainbowcols", ggtheme = theme_minimal())