0% found this document useful (0 votes)
61 views4 pages

Divisive Hierarchical Clustering Using DIANA Technique

1. The document describes performing divisive hierarchical clustering on data from a spreadsheet using the DIANA technique. 2. Key steps include loading libraries, reading in data and selecting columns, running the DIANA clustering algorithm, and plotting dendrograms and cluster plots for 2, 3, and 5 clusters. 3. The clustering is performed multiple times with different numbers of clusters to compare the results.

Uploaded by

mohamed mohsen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views4 pages

Divisive Hierarchical Clustering Using DIANA Technique

1. The document describes performing divisive hierarchical clustering on data from a spreadsheet using the DIANA technique. 2. Key steps include loading libraries, reading in data and selecting columns, running the DIANA clustering algorithm, and plotting dendrograms and cluster plots for 2, 3, and 5 clusters. 3. The clustering is performed multiple times with different numbers of clusters to compare the results.

Uploaded by

mohamed mohsen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

divisive hierarchical clustering using DIANA technique.

1. install and call need libraries:


library(factoextra)
library(readxl)
library(dplyr)
library(cluster)
library(stats)
2. read data from data1.xlsx file, then select columns 2,3:
data1 <- read_excel("C:\\Users\\AAH\\Desktop\\data1.xlsx") #reed Data from data1.xlsx file
mydata <- select(data1,c(2,3)) #select columns 2,3.
3. start Divisive method:
dh=diana(mydata)
dh$dc #Divisive Coefficient
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana")# plot dendrogram
Output:
1. Divisive Coefficient: 0.9633754
2. dendrogram:

4. display clustering data


A. 2 clusters:
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana (2 clusters)")# plot dendrogram
rect.hclust(dh, k = 2, border = 5:10)#2 clusters

clust <- cutree(dh, k = 2)#clustering data in 2 clusters


fviz_cluster(list(data = mydata, cluster = clust))#visualize the result in a scatter plot.
Output:
dendrogram:
Cluster plot:

A. 3 clusters:
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana (3 clusters)")# plot dendrogram
rect.hclust(dh, k = 3, border = 5:10)#5 clusters

clust <- cutree(dh, k = 3)#clustering data in 5 clusters


fviz_cluster(list(data = mydata, cluster = clust))#visualize the result in a scatter plot.
Output:
Dendrogram:

Cluster plot:
A. 5 clusters:
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana (5 clusters)")# plot dendrogram
rect.hclust(dh, k = 5, border = 5:10)#5 clusters

clust <- cutree(dh, k = 5)#clustering data in 5 clusters


fviz_cluster(list(data = mydata, cluster = clust))#visualize the result in a scatter plot.
Output:
dendrogram:

Cluster plot:
Consolidated code:
install.packages("factoextra",dependencies = T)
install.packages("readxl",dependencies = T)
install.packages("dplyr",dependencies = T)
install.packages("cluster",dependencies = T)
install.packages("stats",dependencies = T)
library(factoextra)
library(readxl)
library(dplyr)
library(cluster)
library(stats)

options(tibble.width = Inf) # to show all the columns.


options(tibble.print_max = Inf) # to show all the rows.

data1 <- read_excel("data 1.xlsx") #reed Data from data 1.xlsx file
View(data1)

mydata <- select(data1,c(2,3)) #select columns 2,3.


mydata

#Divisive method:
dh=diana(mydata)
dh$dc #Divisive Coefficient
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana") # plot dendrogram

#2 clusters
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana (2 clusters)") # plot dendrogram
rect.hclust(dh, k = 2, border = 5:10) #2 clusters

clust <- cutree(dh, k = 2) #clustering data in 2 clusters


fviz_cluster(list(data = mydata, cluster = clust)) #visualize the result in a scatter plot.

#3 clusters
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana (3 clusters)") # plot dendrogram
rect.hclust(dh, k = 3, border = 5:10) #5 clusters

clust <- cutree(dh, k = 3) #clustering data in 5 clusters


fviz_cluster(list(data = mydata, cluster = clust)) #visualize the result in a scatter plot.

#5 clusters
pltree(dh, cex = 0.9, hang = -1, main = "Dendrogram of diana (5 clusters)") # plot dendrogram
rect.hclust(dh, k = 5, border = 5:10) #5 clusters

clust <- cutree(dh, k = 5) #clustering data in 5 clusters


fviz_cluster(list(data = mydata, cluster = clust)) #visualize the result in a scatter plot.

You might also like