require(datanugget)
#2-d small example with visualization
X = rbind.data.frame(matrix(rnorm(10^3, sd = 0.3), ncol = 2),
matrix(rnorm(10^3, mean = 1, sd = 0.3), ncol = 2))
#create data nuggets
my.DN = create.DN(x = X,
R = 100,
delete.percent = .1,
DN.num1 = 100,
DN.num2 = 30,
no.cores = 0,
make.pbs = FALSE)
#refine data nuggets
my.DN2 = refine.DN(x = X,
DN = my.DN,
EV.tol = .9,
min.nugget.size = 2,
max.splits = 5,
no.cores = 0,
make.pbs = FALSE)
#plot raw dataset
plot(X)
#transform weights to get colors for plot
w_trans = my.DN2$`Data Nuggets`[, "Weight"]/sum(my.DN2$`Data Nuggets`[, "Weight"])
w_trans = w_trans/quantile(w_trans,0.8)
col = sapply(w_trans, function(t){rgb(0,min(t,1),0)})
#plot refined data nugget centers with weights
#lighter green means more weights
plot(my.DN2$`Data Nuggets`[, c("Center1",
"Center2")],col=col,lty = 2,pch=16, cex=0.5)
#Hierarchical Clustering for data nuggets
DN.h = DN.Whclust(my.DN2)
#print the hclust object
print(DN.h)
#plot the hierarchical tree
plot(DN.h)
#cut the hierarchical tree to get 2 clusters
k2 = cutree(DN.h,2)
table(k2)
#plot the clustering result for data nuggets
plot(my.DN2$`Data Nuggets`[, c("Center1",
"Center2")], col = k2, lty = 2,pch=16, cex=0.5)
Run the code above in your browser using DataLab