I am looking to get an unbalanced training set with a given ratio of classA:classB from a dataset without regarding if it is balanced or not. The point is to analyze the influence of data imbalance on the accuracy. I don't see any built-in function to go about this, so I was wondering what approach I should take. For now, I consider either undersampling or oversampling, but I am worried that it might skew the results too much, as I aim to get class ratios of 10/90, 20/80, ..., 80/20, 90/10.
With a straightforward approach, you can just oversample one of the classes to get the imbalance. You can achieve it with using
SMOTE for example. Usually this technique is used to get a balanced set from imbalanced, but it can also work vice-versa, just oversample only once class.
Some links to check:
https://imbalanced-learn.org/stable/over_sampling.html https://machinelearningmastery.com/random-oversampling-and-undersampling-for-imbalanced-classification/ https://towardsdatascience.com/how-to-effortlessly-handle-class-imbalance-with-python-and-smote-9b715ca8e5a7