I'm trying to figure out a way to assign GPS coordinates to core GPS values.

For example,

I've got tons of store locations (with long & lat coordinates) and I'd like to group them to one of x core GPS groups (cities).

I know how to perform a k-means cluster analysis and let the algorithm identify the clusters itself, but in this case I know how many groups I need and where I'd like their centers to be.

Is there a way I can use the K-NN algorithm to automatically associate GPS coordinates to group centers defined by the user?


PS. I currently program in Stata, but if this task is easier in either Python, R, or SAS, please feel free to post how.

  • $\begingroup$ k-means in its basic form cannot decide on k (you decide on it). $\endgroup$
    – ttnphns
    Commented Aug 21, 2015 at 22:16

1 Answer 1


When you predefine the "clusters" this is called classification.

Use nearest neighbor classification to map each user to the nearest city.

  • $\begingroup$ Thanks for your answer. So if establishing city GPS coordinates is how I define the clusters, is there any tutorial on how to do this and with which program would this be easiest to do? $\endgroup$
    – macsmith
    Commented Aug 22, 2015 at 23:04
  • $\begingroup$ It's so basic, you do not need any program at all. But "nearest neighbor classification" is the search term you need. $\endgroup$ Commented Aug 23, 2015 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.