library("fpc") # Compute DBSCAN using fpc package set.seed(123) db <- fpc::dbscan(df, eps = 0.15, MinPts = 5) # Plot DBSCAN results plot(db, df, main = "DBSCAN", frame = FALSE)
library(RODBC) conn <- odbcConnect("dw", uid = "user1", pwd = "pw") mydata <- sqlQuery(conn,"select * from test order by x") head(mydata) robustz <- function(x) { sigma <- IQR(x) / 1.35 if(sigma == 0) sigma <- sd(x) if(sigma == 0) sigma <- 0.00001 z <- (x - median(x)) / sigma return(z) } x <- mydata[, c("x", "y")] df <- mydata[, c("x", "y")] x$x <- robustz(x$cnt) x$y <- robustz(x$ccu_avg) library("fpc") cl <- fpc::dbscan(x, eps = 0.30, MinPts = 5) plot(cl, df, main = "DBSCAN", frame = FALSE)