![Hands-On Machine Learning with Microsoft Excel 2019](https://wfqqreader-1252317822.image.myqcloud.com/cover/668/36698668/b_36698668.jpg)
Entropy calculation
The frequency table for the combination Outlook-Train outside is as follows:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/7.jpg?sign=1739571696-zoZBuK3j5dwxEV4GkOCgkTRhysiibxPR-0-ed4d4e14c6fb569f241fb33e4cc6757f)
Using these values, we get the entropy of two variables, as shown here in detail:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/376672c9-2d09-4c28-8fab-67e9601dc316.png?sign=1739571696-uCOeSJondXDBfSBYsqyMbsDMw8FWv5Om-0-068a6a4d77340ff7e17b0b3c3f6f8c6b)
p(Sunny).S(Sunny)+p(Overcast).S(Overcast)+p(Rainy)*S(Rainy)=
5/14*(-3/5*log2(3/5)-2/5*log2(2/5)) +
4/14*(-4/4*log2(4/4)-0/4*log2(0/4))+
5/14*(-2/5*log2(2/5)-3/5*log2(3/5))=
0.693
Here, p(Sunny) = (#Yes+#No)/Total entries = (2+3)/14, p(Overcast) = (#Yes+#No)/Total entries = (4+0)/14, and p(Rainy) = (#Yes+#No)/Total entries = (2+3)/14. The entropy values S(v) are calculated using the corresponding probabilities, that is, #Yes or #No over the total #Yes+#No.
The frequency table for the combination Temperature-Train outside is as follows:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/8.jpg?sign=1739571696-MwZQQyL5LZXMZFpOQR6TwwkRrrR2d5Sx-0-4b07b5a4a9c865b857dcf3d415d2fa6d)
Using these values and an analogous calculation, the entropy is shown in detail here:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/eff7388b-ac6d-4b8c-95fa-5d057e97fd1d.png?sign=1739571696-tiMIIoVBY13x41S6JSlIFx439gP0bMZN-0-c7834436f80250e5380ec92c74939cfc)
p(Hot).S(Hot)+p(Mild).S(Mild)+p(Cool)*S(Cool)=
4/14*(-2/4*log2(2/4)-2/4*log2(2/4)) +
6/14*(-4/6*log2(4/6)-2/6*log2(2/6))+
4/14*(-3/4*log2(3/4)-1/4*log2(1/4)) =
0,911
The frequency table for the combination Humidity-Train outside is as follows:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/9.jpg?sign=1739571696-dyEuSlsrPV5qv1NYSq6X4Yp5e3l9QGnp-0-112408d6381d18e5a71c4f432cd47009)
Using these values, we get the entropy as follows:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/91f2ee7e-5fee-497d-8b8a-3a42b9d21d98.png?sign=1739571696-7jSqxdrg6yf48WwMycQLIYz2U554RcSM-0-4efba6f129c5d85c6a6089ad834f398a)
p(High).S(High)+p(Normal).S(Normal)=
7/14*(-3/7*log2(3/7)-4/7*log2(4/7)) +
7/14*(-6/7*log2(6/7)-1/7*log2(1/7))=
0,788
The frequency table for the combination Windy-Train outside is as follows:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/10.jpg?sign=1739571696-3Ew0GKN4TzgBeysCxbxp007wfm8CBuWG-0-f02fdc3b68c715ab8b3588d42dd144cf)
Using these values, we get the entropy as follows:
![](https://epubservercos.yuewen.com/33541B/19470379501493906/epubprivate/OEBPS/Images/ae116dfd-9968-47ba-ad17-fbd5ec08073e.png?sign=1739571696-QwRq7akm8dGNmIGLVtHPD8HTsnBMbFA2-0-42f3db23b2ea4710680182ed2676bf57)
p(True).S(True)+p(False).S(False)=
8/14*(-6/8*log2(6/8)-2/8*log2(2/8)) +
6/14*(-3/6*log2(3/6)-3/6*log2(3/6))
=0,892