1

I would like to draw boundary lines of multiple groups in a two dimensional plane. I know I can draw a contour line to divide only two groups using SVM, but not for multiple groups.

In the sample code below, there are 500 points in 5 groups. But in my actual project, I have millions of points in thousands of groups.

# random 500 points
set.seed(1)
lenPoints = 500
dfPoints = data.frame(
  "x" = runif(n = lenPoints, min = 1, max = 10),
  "y" = runif(n = lenPoints, min = 1, max = 10),
  "grp" = NA
)

# set the first 5 elements as groups 1,2,3,4,5
maxGroup = 5
dfPoints$grp[seq_len(maxGroup)] = seq_len(maxGroup)
dfOrigins = dfPoints[seq_len(maxGroup),]

# assign all the points in one of the 5 groups
for(ctDummy in seq_len(lenPoints - maxGroup)  ){
  (iNa = which(is.na(dfPoints$grp))[1])
  vecTempDist = sqrt( (dfOrigins$x - dfPoints$x[iNa])^2 + (dfOrigins$y - dfPoints$y[iNa])^2 )
  iMin = which.min(vecTempDist)
  dfPoints$grp[iNa] = iMin
}

plot(dfPoints$x, dfPoints$y, col=dfPoints$grp)

# end

enter image description here

stok
  • 375
  • 4
  • 8
  • Is you question about how to _plot_ (known) boundaries, how to find the boundaries (algorithmically), or both? – Fridolin Linder Dec 14 '17 at 03:00
  • I want to draw boundary lines and I don’t know where the boundaries are. So the answer is “both.” – stok Dec 14 '17 at 03:35

0 Answers0