2015-08-09 53 views
0

我試圖繪製DBSCAN結果。這是我迄今爲止所做的。我的距離矩陣是hereR:如何將噪聲簇添加到DBSCAN圖中

dbs55_CR_EUCL = dbscan(writeCRToMatrix,eps=0.006, MinPts = 4, method = "dist") 

plot(writeCRToMatrix[dbs55_CR_EUCL$cluster>0,], 
    col=dbs55_CR_EUCL$cluster[dbs55_CR_EUCL$cluster>0], 
    main="DBSCAN Clustering K = 4 \n (EPS=0.006, MinPts=4) without noise", 
    pch = 20) 

這是劇情: enter image description here

,當我試圖繪製所有羣集包括噪聲集羣,我只能看到我的積2分。 enter image description here

我在尋找什麼是

  1. 噪聲集羣的情節,但用不同的符號加分。類似於以下圖像的東西

enter image description here

  • 燈罩簇區域如在下面的圖片
  • enter image description here

    回答

    2

    噪聲集羣的ID爲0.R圖通常忽略0的顏色,因此如果要顯示噪點(如黑色)那麼你需要做到以下幾點:

    plot(writeCRToMatrix, 
        col=dbs55_CR_EUCL$cluster+1L, 
        main="DBSCAN Clustering K = 4 \n (EPS=0.006, MinPts=4) with noise", 
        pch = 20) 
    

    如果你想爲噪聲不同的符號,那麼你可以做以下(改編自手冊頁):

    library(dbscan) 
    n <- 100 
    x <- cbind(
        x = runif(10, 0, 10) + rnorm(n, sd = 0.2), 
        y = runif(10, 0, 10) + rnorm(n, sd = 0.2) 
    ) 
    
    res <- dbscan::dbscan(x, eps = .2, minPts = 4) 
    plot(x, col=res$cluster, pch = 20) 
    points(x[res$cluster == 0L], col = "grey", pch = "+") 
    

    這裏是代碼,將創建每個簇的陰影凸包

    library(ggplot2) 
    library(data.table) 
    library(dbscan) 
    
    
    dt <- data.table(x, level=as.factor(res$cluster), key = "level") 
    hulls <- dt[, .SD[chull(x, y)], by = level] 
    
    ### get rid of hull for noise 
    hulls <- hulls[level != "0",] 
    
    cols <- c("0" = "grey", "1" = "red", "2" = "blue") 
    
    ggplot(dt, aes(x=x, y=y, color=level)) + 
        geom_point() + 
        geom_polygon(data = hulls, aes(fill = level, group = level), 
        alpha = 0.2, color = NA) + 
        scale_color_manual(values = cols) + 
        scale_fill_manual(values = cols) 
    

    希望這會有所幫助。

    +0

    謝謝邁克爾 – SriniShine