DBSCAN Clustering

Examples

## Example 1
# ---
# Question: Perform DBSCAN Clustering on the given IRIS Dataset.
# Reference: https://rpubs.com/kalipradeep/dbscan
# ---
# OUR CODE GOES BELOW
# 

# Importing the required package
# ---
# 
install.packages("dbscan")

# Loading the required library
# ---
# 
library("dbscan")

# Lets load our Iris dataset
# ---
# 
m<-read.csv("http://bit.ly/IrisDataset")
head(m)

# Removing the class label 
# ---
#
m1<-m[,c(1,2,3,4)]
head(m1)

# Applying our DBSCAN algorithm
# ---
# We want minimum 4 points with in a distance of eps(0.4)
# 
db<-dbscan(m1,eps=0.4,MinPts = 4)

# Printing out the clustering results
# ---
# 
print(db)

# We also plot our clusters as shown
# ---
# The dataset and cluster method of dbscan is used to plot the clusters.
# 
hullplot(m1,db$cluster)

Challenges

## Challenge 1
# ---
# Question: For the given dataset, perform DBSCAN clustering.
# ---
# Hint: Remove the label class
# ---
# Dataset url = http://bit.ly/MSDBSCANClusteringDataset
# ---
# OUR CODE GOES BELOW
# 

# Lets load our Iris dataset
# ---
# 
p<-read.csv("http://bit.ly/MSDBSCANClusteringDataset", sep = ',', header = TRUE)
head(p)

# Removing the class label 
# ---
#
m1<-m[,c(1,2,3,4)]
head(m1)

# Applying our DBSCAN algorithm
# ---
# We want minimum 4 points with in a distance of eps(0.4)
# 
db<-dbscan(m1,eps=0.4,MinPts = 4)

# Printing out the clustering results
# ---
# 
print(db)

# We also plot our clusters as shown
# ---
# The dataset and cluster method of dbscan is used to plot the clusters.
# 
hullplot(m1,db$cluster)

## Challenge 2
# ---
# Question: Perform DBSCAN clustering on the following toy dataset.
# ---
# Dataset url = http://bit.ly/MSDBSCANClusteringDataset2
# ---

# Lets load our Iris dataset
# ---
# 
y<-read.csv("http://bit.ly/MSDBSCANClusteringDataset2", sep = ',', header = TRUE)
head(y)

# Removing the class label 
# ---
#
m3<-y[,c(2,3,4,5)]
head(m3)

# Applying our DBSCAN algorithm
# ---
# We want minimum 4 points with in a distance of eps(0.4)
# 
db3<-dbscan(m3,eps=0.7,MinPts = 2)

# Printing out the clustering results
# ---
# 
print(db3)

# We also plot our clusters as shown
# ---
# The dataset and cluster method of dbscan is used to plot the clusters.
# 
hullplot(m3,db3$cluster)



```R
## Challenge 3
# ---
# Question: Apply and Visualize DBCAN clustering on the following dataset.
# ---
# Dataset url = http://bit.ly/MSDBSCANClusteringDataset3
# ---
# Lets load our 
# ---
# 
k<-read.csv("http://bit.ly/MSDBSCANClusteringDataset3")
head(k)

# Removing the class label 
# ---
#
m1<-m[,c(1,2,3,4)]
head(m1)

# Applying our DBSCAN algorithm
# ---
# We want minimum 4 points with in a distance of eps(0.4)
# 
db4<-dbscan(k,eps=0.4,MinPts = 4)

# Printing out the clustering results
# ---
# 
print(db4)

# We also plot our clusters as shown
# ---
# The dataset and cluster method of dbscan is used to plot the clusters.
# 
hullplot(k,db4$cluster)