In a research study I have a list of countries and data about them.

  • GDP
  • Population
  • Oil exports
  • Oil imports
  • Percentage of electricity produced with renewable energies
  • Urbanization
  • Percentage of GDP put into research in renewable energies

Now I would like to cluster these countries into three groups. In the end the group should be equivalent to:

  • Countries with high ecological standards
  • Countries with medium ecological standards
  • Countries with low ecological standards

These 3 categories are ordered. I would like to run the model additionally for 5 categories.

Which clustering algorithm would be most appropriate? Is k-means a good choice in this case? Which dangers arise when I use k-means? If you have some code in R solving a similar problem I would also be grateful.


3 Answers 3


This is, I think, not a problem for cluster analysis at all. Cluster analysis is unsupervised learning and you want some form of supervision.

What you seem to want is factor analysis, not cluster analysis, but maybe not FA either. If you already know what "ecological standards" means, you could derive a variable yourself. If not, then factor analysis of your existing variables might give you a factor that you think of as ecological standards.

That factor might break up into three groups, but it might not. I am not srue why you want this to break up into groups (and exactly three). I think it would be better treated, for almost all purposes, as a continuous variable.

But if you already know which country belongs in which group, then you have a classification task, which calls for other methods.

  • $\begingroup$ The problem is that I can neither observe the factor nor any proxy variable for the groups. As it is unlabelled data supervised learning does not make sense to me. $\endgroup$
    – Ferdi
    Mar 14, 2017 at 12:40
  • $\begingroup$ If you propose factor analysis, which factor analysis algorithm would be the best? $\endgroup$
    – Ferdi
    Mar 14, 2017 at 12:41
  • $\begingroup$ You don't have unsupervised learning because you already know what you want to get. k-groups cluster analysis will give you 3 groups, but there's no assurance they will be divided into the 3 that you want. For factor analysis, I don't have a strong preference as to which algorithm. Try a few and see which works best for your purposes. $\endgroup$
    – Peter Flom
    Mar 14, 2017 at 12:44
  • 1
    $\begingroup$ +1 as you mentioned in the answer. clustering is more data driven approach. But OP wants some knowledge driven / rule based classification method. $\endgroup$
    – Haitao Du
    Mar 14, 2017 at 13:49
  • 1
    $\begingroup$ Thank you for your great answer. It is a great help to my problem. $\endgroup$
    – Ferdi
    Mar 14, 2017 at 14:05

You might take a look at the Wikibooks Example that purports to do almost exactly what you are asking about. However, I don't really recommend this.

  1. The "Case Study" given in the posting is poorly executed. The problem there is that the author failed to scale the variables so that only one variable (Per Capita Income) actually makes any difference in the clustering.

  2. To paraphrase @PeterFlomm 's answer, clustering is not classification. If you apply a clustering algorithm, you will get some clusters. However, if you have in mind some underlying classification, there is no reason to believe that your clustering will correspond to the classes. This example is a great case in point. You want clusters that represent ecological standards. But there are many other classifications of countries that are possible. Why wouldn't the clustering just be rich and poor countries? Long life expectancy and short life expectancy? Countries with rich natural resources and countries without? Countries with a free press and countries without? The clustering cannot simultaneously reflect all of these things unless they all coincide (which is dubious). Why should you imagine that the clustering corresponds to your collection of classes? If you want to classify, you must figure out how to solve that problem. Clustering where you want classification is a poor choice.


Clustering will not give you clusters like 'high ecological standards'. That is classification.

Therefore, I suggest that you try to either

  1. Define 'high', 'medium' and 'low' expected values for each attribute, and try nearest neighbor classification on these three data points (and carefully adjust data scaling to improve the results!)

  2. Label examples, such as united states: medium environmental standards and then train a SVM classifier.

Beware that many methods are sensitive to scale. An attribute in the range of billions will overrule attributes which only change a few points. You need to spend a lot of time in optimizing your preprocessing.

  • 1
    $\begingroup$ Thank you. Your answer is great. Unfortunately the dataset is too big for labelling the whole data by hand. How can I proceed if I can label only a small fraction? Why do you propose a SVM for classification with 3 labels? $\endgroup$
    – Ferdi
    Mar 17, 2017 at 8:30
  • 2
    $\begingroup$ You don't need to label everything. Only a training set. $\endgroup$ Mar 18, 2017 at 19:19

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.