def compensate_imbalance(data): total_data = len(data) clean_data = [item for n, item in enumerate(data) if item not in data[:n]] weight_list = [data.count(item)/total_data for item in clean_data] return weight_list
Here is what the above code is Doing:
1. It’s creating a list of all the unique values in the data.
2. It’s creating a list of weights for each unique value.
3. It’s returning the weight list.