I wrote for loop to calculate the probability for conditional entropy but if the statement is not working correctly for the last i in the loop.
The array I am trying to iterate through:
joint_age_dia = np.c[data["Ageover50"],data["diabetic"]]
joint_age_dia
array([['True', 'yes'],
['False', 'yes'],
['False', 'no'],
['True', 'yes'],
['True', 'no'],
['True', 'yes'],
['False', 'no'],
['False', 'no'],
['True', 'yes'],
['False', 'no']], dtype=object)
The for loop that I create to get the counts of (Y|X=True), (Y|X=False) is
for i in range(len(joint_age_dia)):
if joint_age_dia[i][1] == 'yes' and joint_age_dia[i][0] == 'True':
yy_t += 1
if joint_age_dia[i][1] == 'yes' and joint_age_dia[i][0] == 'False':
yy_f += 1
if joint_age_dia[i][1] == 'no' and joint_age_dia[i][0] == 'True':
yn_t += 1
if joint_age_dia[i][1] == 'no' and joint_age_dia[i][0] == 'False':
yn_f += 1
else:
None
print(yy_t) # 4
print(yy_f) # 1
print(yn_t) # 2
print(yn_f) # 3
If the loop works correctly yn_t is supposed to be 1 and yn_f should be 4 but I noticed when i = 10 it counts the last list of the array wrong (Since it's 'no' when the left side element is 'False', yn_f should have been incremented).
I can't figure out what went wrong...