Experiment 9

Step 1: Import the required package.

library("dbscan")

Step 2: Import the dataset

Here we are using IRIS data set- This dataset tells details about flower species.

m<-read.csv("C:/Users/pradeep/OneDrive/dm,cns,cp and JKC/data mining/dm files 2020 passouts/lab/iris.csv")

head(m)
##   sepal_length sepal_width petal_length petal_width species
## 1          5.1         3.5          1.4         0.2  setosa
## 2          4.9         3.0          1.4         0.2  setosa
## 3          4.7         3.2          1.3         0.2  setosa
## 4          4.6         3.1          1.5         0.2  setosa
## 5          5.0         3.6          1.4         0.2  setosa
## 6          5.4         3.9          1.7         0.4  setosa

Step 3: Remove the class label

As we are doing clustering (Unsupervised learning), we donโ€™t need class label.

m1<-m[,c(1,2,3,4)]
head(m1)
##   sepal_length sepal_width petal_length petal_width
## 1          5.1         3.5          1.4         0.2
## 2          4.9         3.0          1.4         0.2
## 3          4.7         3.2          1.3         0.2
## 4          4.6         3.1          1.5         0.2
## 5          5.0         3.6          1.4         0.2
## 6          5.4         3.9          1.7         0.4

Step 4: Apply DBSCAN algorithm.

# We want minimum 4 points with in a distance of eps(0.4)
db<-dbscan(m1,eps=0.4,MinPts = 4)
## Warning in dbscan(m1, eps = 0.4, MinPts = 4): converting argument MinPts
## (fpc) to minPts (dbscan)!
print(db)
## DBSCAN clustering for 150 objects.
## Parameters: eps = 0.4, minPts = 4
## The clustering contains 4 cluster(s) and 25 noise points.
## 
##  0  1  2  3  4 
## 25 47 38 36  4 
## 
## Available fields: cluster, eps, minPts

Step 5: Plot the clusters.

# the dataset and cluster method of dbscan is used to plot the clusters.

hullplot(m1,db$cluster)