1

Balancing Data

Unsolved
Data Wrangling

Difficulty: 2 | Problem written by zeyad_omar
Sometime in ML projects, the dataset is imbalanced, meaning the number of elements in each class is totally different. To address this, engineers often use a weighting technique to compensate that imbalance (as it is difficult to get more data).

For example, the class with the smaller size might be assigned a larger weight than the class with the larger size.

In this problem, you are given a 1D vector containing a dataset of 2 or more classes and you are asked to assign weights to each of the classes such that the sum of the weights is 1.

Return a list with the weight of each class (arrange the classes by the order they appear in the given dataset).

Sample Input:
<class 'list'>
data: [1, 1, 1, 2]

Expected Output:
<class 'list'>
[0.75, 0.25]

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Nostrum dolorum voluptates beatae facilis tempore praesentium qui sequi soluta?

Asperiores illum inventore voluptate suscipit, blanditiis sequi odit, ipsam eum minus enim maiores vel doloremque dolores aliquam hic asperiores, doloribus ipsa iste possimus nisi hic? Consequuntur animi fugiat, vel nam inventore ipsa tempore doloribus voluptatum eaque voluptates officiis veritatis, tempora animi placeat nesciunt illo vero, eos rerum omnis? Dolore beatae dicta eum pariatur similique architecto adipisci, ipsam nam enim nostrum soluta corporis quidem sint reprehenderit deleniti expedita neque, quibusdam corrupti qui non sunt iure, autem perferendis optio amet officiis molestiae nemo, ratione mollitia maxime laborum cumque facilis.

Voluptatum perferendis pariatur ipsum, a magni eos corrupti ipsam architecto reiciendis expedita velit ratione quasi, velit vitae fugiat animi mollitia consectetur dolorum qui debitis? Molestias odio similique temporibus fuga odit totam, adipisci expedita voluptatum mollitia sapiente et quidem id odit illum ex, eos dignissimos ullam ea fugit voluptate adipisci doloribus unde facere fugiat ab, sequi aliquid eos soluta minus, eius rem consequatur dignissimos dolore necessitatibus qui fuga eos magni? Autem delectus error veritatis, commodi fugit recusandae quas perspiciatis expedita autem excepturi architecto?

This is a premium feature.
To access this and other such features, click on upgrade below.

Ready.

Input Test Case

Please enter only one test case at a time
numpy has been already imported as np (import numpy as np)