2016-01-21 213 views
-1

我是R新手,我有一個我不確定的請求是否可能。我們有許多零售地點,我的老闆想用親和力傳播方式將其分爲羣集。我們不會根據地理位置進行聚類。一旦他找到了他喜歡的配置,他希望能夠輸入其他位置來確定它們應該落入哪些集合集羣。使用R中的apcluster軟件包,可以對非集羣數據點「評分」

我所能想出的唯一解決方案是使用相同的選項並重新聚集原始點和添加新的點,但是我相信這可能會改變結果。

我是否理解這個權利,還是有其他選擇?

回答

2

集羣不是分類的直接替換。

很少有聚類算法可以有意義地整合新信息。

您的問題通常的做法不過是簡單的:

  1. 做集羣。
  2. 使用集羣作爲標籤的分類標記
  3. 訓練分類
  4. 分類應用到新的數據
2

對不起,我遲到的答案,我只是順便絆了你的問題。

我同意Anony-Mousse的回答:聚類是第一步,分類是第二步。不過,我不確定這是否是最佳選擇。 Elena601b顯然是在討論一個真正具有空間數據的任務,所以我的印象是,最好的方法是首先進行聚類,然後通過查找最接近的聚類範例來「分類」新的點/樣本/位置。下面是合成數據的一些代碼:

## if not available, run the following first: 
## install.packages("apcluster") 

library(apcluster) 

## create four synthetic 2D clusters 
cl1 <- cbind(rnorm(30, 0.3, 0.05), rnorm(30, 0.7, 0.04)) 
cl2 <- cbind(rnorm(30, 0.7, 0.04), rnorm(30, 0.4, .05)) 
cl3 <- cbind(rnorm(20, 0.50, 0.03), rnorm(20, 0.72, 0.03)) 
cl4 <- cbind(rnorm(25, 0.50, 0.03), rnorm(25, 0.42, 0.04)) 
x <- rbind(cl1, cl2, cl3, cl4) 

## run apcluster() (you may replace the Euclidean distance by a different 
## distance, e.g. driving distance, driving time) 
apres <- apcluster(negDistMat(r=2), x, q=0) 

## create new samples 
xNew <- cbind(rnorm(10, 0.3, 0.05), rnorm(10, 0.7, 0.04)) 

## auxiliary predict() function 
predict.apcluster <- function(s, exemplars, newdata) 
{ 
    simMat <- s(rbind(exemplars, newdata), 
       sel=(1:nrow(newdata)) + nrow(exemplars))[1:nrow(exemplars), ] 
    unname(apply(simMat, 2, which.max)) 
} 

## assign new data samples to exemplars 
predict.apcluster(negDistMat(r=2), x[[email protected], ], xNew) 

## ... the result is a vector of indices to which exemplar/cluster each 
## data sample is assigned 

我可能會在未來的包裝的版本中增加這樣一個predict()方法(我是包的維護者)。我希望有所幫助。

相關問題