<p>Depending on what you are trying to model, it may or may not be correct to do so.</p>
<p>Training on an imbalanced dataset will generally make your model overfit those elements that appear more often, which leads to bias towards those ones at best or no understanding of the underrepresented samples at worst. If you are trying to model the natural occurrences of some information, then an unbalanced dataset in essence has a prior probability applied to it already, so the resulting bias may be desired. In these cases, the number of elements per class, say, <em>is</em> part of the actual information. Such a bias can be (un-)modeled artificially too, however, e.g. by applying a scaling factor for classification (e.g. through class weights), etc. To avoid such bias, boosting and ensemble methods such as Xgboost (or Adaboost in more trivial cases) or just Random Forests work relatively well. If you have the time, k-fold cross validation can help reducing the error further.</p>
<p>To make sure every sample is adequately represented, you may choose to oversample the underrepresented classes or undersample the overrepresented ones. In order to determine correct likelihoods, make sure to capture the prior distribution as well and use it to shape the posterior. Data augmentation may help you if the number of samples is low; depending on your case, synthetic data generation might be a good approach. You could try, say, training a GAN only on the underrepresented samples and use that to generate more - as in idea: train it on all available data first, then change the discriminator loss to force it to forge and recognize the underrepresented classes only. Without entering the Deep Learning domain, techniques such as <a href="https://arxiv.org/abs/1106.1813" rel="nofollow noreferrer">SMOTE</a> or ADASYN may work. Both are available in the <a href="https://github.com/scikit-learn-contrib/imbalanced-learn/" rel="nofollow noreferrer"><code>imblearn</code></a> Python package which builds on scikit-learn.</p>
<p>Lastly, carefully selecting the loss metric may help. You can find more (and more detailed) information in papers such as <a href="https://link.springer.com/article/10.1186/s40537-019-0192-5" rel="nofollow noreferrer">Survey on deep learning with class imbalance</a>.</p>
Is it okay to build a model on imbalanced data?
<p><strong>Background -</strong>
The dataset I am working on is highly imbalanced and the number of classes is 543. The data is bounded by date. After exploring the data over a span of 5 years I came to know the imbalance is inherent and its persistent. The test data which the model will get will also be bounded by a date range and it will also have a similar imbalance.</p>
<p>The reason for the imbalance in the data is different amount of spend, popularity of a product. Handling imbalance would do injustice to the business.</p>
<p><strong>Questions -</strong>
In such a case, is it okay to proceed with building model on imbalanced data?</p>
<p>The model would be retrained every month on the new data and it would be used for predictions once in a month.</p>