Cylindrical Clustering in R - clustering timestamp with other data

后端 未结 2 1185
悲哀的现实
悲哀的现实 2021-01-14 17:09

I\'m learning R and I have to cluster numeric data with a timestamp field. One of the parameters is a time, and since the data is strictly day-night dependent, I want to ta

2条回答
  •  Happy的楠姐
    2021-01-14 17:19

    Here is such a mapping of h to m where h is the time in hours (and fraction of an hour). Then we try kmeans and at least in this test it seems to work:

    h <- c(22, 23, 0, 1, 2, 10, 11, 12)
    ha <- 2*pi*h/24
    m <- cbind(x = sin(ha), y = cos(ha))
    
    kmeans(m, 2)$cluster # compute cluster assignments via kmeans
    ## [1] 2 2 2 2 2 1 1 1
    

提交回复
热议问题