I have a panads dataframe from wiki
Outlook Temperature Humidity Wind Play
Sunny Hot High False No
Sunny Hot High True No
Overcast Hot High False Yes
Rainy Mild High False Yes
Rainy Cool Normal False Yes
Rainy Cool Normal True No
Overcast Cool Normal True Yes
Sunny Mild High False No
Sunny Cool Normal False Yes
Rainy Mild Normal False Yes
Sunny Mild Normal False Yes
Overcast Mild High True Yes
Overcast Hot Normal False Yes
Rainy Mild High True No
and I want to see if the outlook
is sunny
/overcast
/rainy
, how many times are they gonna play and then to calculate the Shannon entropy for each of the outcome, so the desire outcome looks like
Outlook Yes No Count of each group Entropy
sunny 2 3 5 0.971
overcast 4 0 4 0.000
rainy 3 2 5 0.971
where Entropy
is given by the formula -((yes/count)log_2(yes/count) + (no/count)log_2(no/count))
So for example, the entropy for sunny
is -((2/5)log_2(2/5)+(3/5)log_2(3/5))=0.971