Guest User

Untitled

a guest
Feb 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. library(dbscan)
  2. ## generating data -------------------------
  3. set.seed(1839)
  4. n <- 5000
  5. x <- rbeta(n, .4, .4)
  6. y <- rbinom(n, 1, x)
  7. z <- ifelse(y == 1, 0, 1)
  8. dat <- data.frame(x, y, z)
  9.  
  10. ## selecting eps ---------------------------
  11. kNNdistplot(dat, 9)
  12. abline(h = .0045) # at the elbow
  13.  
  14. ## clustering ------------------------------
  15. # redundant column
  16. set.seed(1839)
  17. c1 <- dbscan(dat, .0045, 9)
  18.  
  19. # no redundant columns
  20. set.seed(1839)
  21. c2 <- dbscan(dat[, -3], .0045, 9)
  22.  
  23. ## equivalent? -----------------------------
  24. all.equal(c1$c, c2$c)
Add Comment
Please, Sign In to add comment