# Multiclass data redistribution

I want to redistribute the data in classes according to new proportions and wonder what is the optimal way to do it. For example I have

10 30 60 elements in each class a,b,c

and apparently the fractions in each class are as follows:

0.1 0.3 0.6


What if I want to set the fractions as follows:

0.3 0.2 0.5


and to throw away the other data. New data cannot be generated and the maximum number of data points should be kept. Can it be generalized to a hundred of classes?

UPD: I derived some minimization problem:

$$min_\textbf{n} \; f(\textbf{n}) = - \sum p^{new}_i \log{\hat p_i} = - \sum p^{new}_i \log{(\hat n_i/ \hat N)}$$

$$= \log(\hat N)- \sum p^{new}_i \log{(\hat n_i)}$$ s.t $$\hat n_i \le n_i^c \; , \forall i \in 1:C$$ $$\hat N = \sum_i \hat n_i$$

But I don't know how to fomulate the condition that $$\hat n_i$$ should be also maximized at the same time.

where $$\hat n$$ is a number of elements in the i-th class, that i'm looking for, $$N$$ is total number of elements and $$C$$ is a number of classes. $$p^{new}_i$$ is a class partition. $$n_i$$ is an original number of elements in the given class

How to solve it?

• a simple way is to: 1) remove one data from the most populated class and re-calculate the proportions. 2) go to step 1) untill the desired proportions are met (within some reasonable bounds) Jun 1 at 18:28
• there can be variations on the above algorithm, eg if a certain min number of data points should be in each class, then step 1) can go tothe next most populated class and so on.. Jun 1 at 18:29
• Doesn't it take too long? My dataset size is of the order of $10^5$, the number of classes are under 10 but a few dozens should be treated as well Jun 1 at 20:36
• You can use Random Under Sampler?? Jun 2 at 8:00
• You can remove more than one data item at the same step, if it is faster. There are many variations of that simple algorithm Jun 2 at 8:08