Thank you so much for your response. As mentioned before I am a novice in AI so there is a good chance I have made a mistake. The dataset I use is the same dataset they have provided for week 1 lab (AI for medical diagnosis). This dataset has 14 classes (diseases) and contains 1000 samples (images). However, the dataset is imbalanced. This is not part of the assignment and I just did this out of curiosity. Here are the steps I have done:
1- create a function for calculating the weighted loss
def weighted_binary_crossentropy(y_true, y_pred, w_p, w_n):
2- load the dataset
train_df = pd.read_csv("../input/arxiv-org-abs-1705-02315/Files/home/jovyan/work/data/nih/train-small.csv")
3- remove columns {‘Image’, ‘Patient Id’}
So after removing my df contains only 14 columns (diseases) and 1000 rows, all values are either 0 or 1
4- calculate y_true (below is the output)
array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]])
5- calculate y_pred
Shape of y_pred: (1000, 14)
Example of y_pred:
[[0.106 0.02 0.033 ... 0.021 0.01 0.038]
[0.106 0.02 0.033 ... 0.021 0.01 0.038]
[0.106 0.02 0.033 ... 0.021 0.01 0.038]
...
[0.106 0.02 0.033 ... 0.021 0.01 0.038]
[0.106 0.02 0.033 ... 0.021 0.01 0.038]
[0.106 0.02 0.033 ... 0.021 0.01 0.038]]
6- calculate w_p
array([0.894, 0.98 , 0.967, 0.984, 0.872, 0.987, 0.986, 0.998, 0.825,
0.955, 0.946, 0.979, 0.99 , 0.962])
7- calculate w_n
array([0.106, 0.02 , 0.033, 0.016, 0.128, 0.013, 0.014, 0.002, 0.175,
0.045, 0.054, 0.021, 0.01 , 0.038])
8- calculate the weighted loss
1660.926470376899
Not sure if sharing the whole code is allowed. If it is, I am happy to share the code here. Thanks so much for your time and your professional help.