-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbalance.py
More file actions
32 lines (25 loc) · 701 Bytes
/
balance.py
File metadata and controls
32 lines (25 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import typing as t
import numpy as np
import math
"""## 2.6 Class Imbalance Measures
### 2.6.1 Entropy of class proportions (C1)
"""
def ft_C1(cls_n_ex: np.ndarray) -> float:
nc = len(cls_n_ex)
n = sum(cls_n_ex)
summation = 0
for i in range(nc):
pi = cls_n_ex[i]/n
summation = summation + pi * math.log(pi)
aux = 1 + summation / math.log(nc)
return aux
"""### 2.6.2 Imbalance ratio (C2)"""
def ft_C2(cls_n_ex: np.ndarray) -> float:
nc = len(cls_n_ex)
n = sum(cls_n_ex)
summation = 0
for i in range(nc):
summation = summation + cls_n_ex[i]/(n - cls_n_ex[i])
aux = ((nc - 1)/nc) * summation
aux = 1 - (1/aux)
return aux