How can we classify text in to given specific number of clusters in python? I'm aware that the number of clusters can be specified using some mechanisms like k-means but I need to classify the given to specific categories.

Ex: I'm having a corpus containing newspaper articles and I want to cluster them pertaining to sports, foreign and local.

Is there anyway to achieve this in python? I've googled but could not find a good match.

Any help in this regard is highly appreciated.

Thanks in advance!!


1 Answer 1


So, Clustering is "Unsupervised" learning : You make groups in which elements look like each-other. In Unsupervised learning, you don't have a Label that you look for.

Here, your problem is to Classify text between 3 categories : Sports, Foreign, Local. Those 3 categories ARE labels : You know you have news about those 3 subjects, and want to make a model that learns characteristics of those 3 categories to automatically assign a label to a new unknown article : This is called Classification, which is Supervised learning. Since you have more than 2 labels (classification is usually Yes or No), you're in a "Multi Label Text Classification Problem". If you're starting in Data Science, that's a really tough subject, far from easy.


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.