I have a merchants dataset with 800,000 samples and 18,000 labels. Each sample is associated with a single label and the labels are independent.

An example sample looks like

description, label
int'l 0028240525 amazon uk retail amazon.co.uk, Amazon

In addition to the existing samples there will be new retailers added to the dataset. In this case there may well only be a single sample for that new retailer.

To summarise, I need a classifier that

  1. handles a large number of labels (~18,000, independent, single label per sample)
  2. is able to classify undersampled labels (i.e. a single retailer)

Is there an approach that will handle both? Perhaps two separate classifiers makes more sense?

  • 1
    $\begingroup$ Out of curiosity, what classifier did you use and how effective it was with so many labels? $\endgroup$
    – Outcast
    Jan 26, 2022 at 13:12

3 Answers 3


For multiclass classification problems there are multiple algorithms which are inherently built in a way to be able to solve them. Some examples: kNN, naive bayes, decision trees...

For the performance to be accurate on all labels and for the classifier to show little bias, you can use other approaches: you can oversample minority classes or undersample majority classes, in a way that all the labels have the same number of points associated with them.

Here you can find some interesting answers about how to fight against class imbalances on decision tree classification: https://stats.stackexchange.com/questions/28029/training-a-decision-tree-against-unbalanced-data


kNN is a lazy eval problem, and at production will take some time to predict. The classifier depends on the problem really

For imbalance, you can do the following: undersample, oversample. You can also go with class_weight parameter while building the classifier Do check https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html


I think your problem is a few-shot learning problem. articles on this topic can be helpful for you.

You can see a brief introduction of this topic here.


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.