Back to the 2023 paper

Module 3: Classification and Prediction

20237m

Build a decision tree using the training data in the table given below. Divide the height attribute into ranges as follows:

[0,1.6],[1.6,1.7],[1.7,1.8],[1.8,1.9],[1.9,2.0],[2.0,5.0][0, 1.6], \quad [1.6, 1.7], \quad [1.7, 1.8], \quad [1.8, 1.9], \quad [1.9, 2.0], \quad [2.0, 5.0]

Gender Height (m) Class
F 1.6 Short
M 2 Tall
F 1.9 Medium
F 1.88 Medium
F 1.7 Short
M 1.85 Medium
F 1.6 Short
M 1.7 Short
M 2.2 Tall
M 2.1 Tall
F 1.8 Medium
M 1.95 Medium
F 1.9 Medium
F 1.8 Medium
F 1.75 Medium
Worked SolutionAI Assisted

Q4(a) - Building a Decision Tree (ID3, Information Gain)

Method. At every node we test the attribute that yields the largest information gain, i.e. the largest reduction of entropy (class impurity):

H(S)=−∑ipilog⁡2pi,Gain(S,A)=H(S)−∑v∈Values(A)∣Sv∣∣S∣H(Sv)H(S)=-\sum_{i}p_i\log_2 p_i, \qquad Gain(S,A)=H(S)-\sum_{v\in Values(A)}\frac{|S_v|}{|S|}H(S_v)

Height binning. A value lying exactly on a boundary is taken into the higher range, so the given ranges are read as [0,1.6),[1.6,1.7),[1.7,1.8),[1.8,1.9),[1.9,2.0),[2.0,5.0][0,1.6),[1.6,1.7),[1.7,1.8),[1.8,1.9),[1.9,2.0),[2.0,5.0]. (With the opposite convention every range comes out pure and the tree is even shallower; the choice of the root attribute does not change.)

Step 1 - Count tables (15 records)

Class counts inside each height range:

Height range Short Medium Tall Total
[0,1.6)[0,1.6) 0 0 0 0
[1.6,1.7)[1.6,1.7) 2 0 0 2
[1.7,1.8)[1.7,1.8) 2 1 0 3
[1.8,1.9)[1.8,1.9) 0 4 0 4
[1.9,2.0)[1.9,2.0) 0 3 0 3
[2.0,5.0][2.0,5.0] 0 0 3 3
Total 4 8 3 15

Class counts by gender:

Gender Short Medium Tall Total
F 3 6 0 9
M 1 2 3 6
Total 4 8 3 15

Step 2 - Entropy of the whole data set

H(S)=−415log⁡2415−815log⁡2815−315log⁡2315=0.5085+0.4837+0.4644=1.4566 bitsH(S)=-\frac{4}{15}\log_2\frac{4}{15}-\frac{8}{15}\log_2\frac{8}{15}-\frac{3}{15}\log_2\frac{3}{15}=0.5085+0.4837+0.4644=\mathbf{1.4566\ \text{bits}}

Step 3 - Candidate splits

(a) Height - multi-way split over the given ranges

Only the range [1.7,1.8)[1.7,1.8) is impure (2 Short + 1 Medium):

H([1.7,1.8))=−23log⁡223−13log⁡213=0.3900+0.5283=0.9183H([1.7,1.8))=-\frac{2}{3}\log_2\frac{2}{3}-\frac{1}{3}\log_2\frac{1}{3}=0.3900+0.5283=0.9183

All other non-empty ranges are pure, so their entropy is 0. Therefore

Gain(Height)=1.4566−315(0.9183)=1.4566−0.1837=1.2729Gain(\text{Height})=1.4566-\frac{3}{15}(0.9183)=1.4566-0.1837=\mathbf{1.2729}

(b) Gender - two-way split

H(F)=−39log⁡239−69log⁡269=0.5283+0.3900=0.9183H(F)=-\frac{3}{9}\log_2\frac{3}{9}-\frac{6}{9}\log_2\frac{6}{9}=0.5283+0.3900=0.9183

H(M)=−16log⁡216−26log⁡226−36log⁡236=0.4308+0.5283+0.5000=1.4591H(M)=-\frac{1}{6}\log_2\frac{1}{6}-\frac{2}{6}\log_2\frac{2}{6}-\frac{3}{6}\log_2\frac{3}{6}=0.4308+0.5283+0.5000=1.4591

Gain(Gender)=1.4566−(915×0.9183+615×1.4591)=1.4566−1.1346=0.3219Gain(\text{Gender})=1.4566-\left(\frac{9}{15}\times0.9183+\frac{6}{15}\times1.4591\right)=1.4566-1.1346=\mathbf{0.3219}

(c) Binary threshold splits on height (cross-check)

Split Left class counts (S, M, T) Right class counts (S, M, T) Gain
height < 1.7 (2, 0, 0) (2, 8, 3) 0.300
height < 1.8 (4, 1, 0) (0, 7, 3) 0.628
height < 1.9 (4, 5, 0) (0, 3, 3) 0.462
height < 2.0 (4, 8, 0) (0, 0, 3) 0.722

Root = Height, because 1.2729 is by far the largest gain (Gender gives only 0.3219).

Step 4 - Grow each branch

  • [0,1.6)[0,1.6) - no records, ignored.
  • [1.6,1.7)[1.6,1.7) - 2 Short, already pure, so leaf = Short.
  • [1.7,1.8)[1.7,1.8) - 2 Short + 1 Medium, so split with the remaining attribute Gender:
    • F gives 1 Short (1.70 m) and 1 Medium (1.75 m): a 1-1 tie, entropy 1.0.
    • M gives one record (1.70 m, Short): pure, leaf = Short.
    • Split gain =0.9183−(23×1+13×0)=0.2516>0=0.9183-\big(\frac{2}{3}\times1+\frac{1}{3}\times0\big)=0.2516>0, so the split is justified.
  • [1.8,1.9)[1.8,1.9) - 4 Medium, pure, leaf = Medium.
  • [1.9,2.0)[1.9,2.0) - 3 Medium, pure, leaf = Medium.
  • [2.0,5.0][2.0,5.0] - 3 Tall, pure, leaf = Tall.

Final decision tree

                          [ Height ]
    +-----------+-----------+-------------+------------+------------+------------+
 [0,1.6)    [1.6,1.7)   [1.7,1.8)     [1.8,1.9)   [1.9,2.0)   [2.0,5.0]
  empty        Short        Gender         Medium      Medium       Tall
                              |
                 +------------+------------+
                 F                        M
             Short *                    Short
         (1 Short, 1 Medium)

Resulting classification rules

  1. Height ∈[2.0,5.0]\in[2.0,5.0] gives Tall
  2. Height ∈[1.8,2.0)\in[1.8,2.0) gives Medium
  3. Height ∈[1.6,1.7)\in[1.6,1.7) gives Short
  4. Height ∈[1.7,1.8)\in[1.7,1.8) and Gender = M gives Short; Gender = F is a 1-1 tie broken by any fixed rule (e.g. Short)

The tree classifies 14 of the 15 training records correctly (93%); the only ambiguity is the female pair inside [1.7,1.8)[1.7,1.8), which no available attribute can separate.

Similar questions

Data MiningBuild a decision tree using the training data in the table given below. Divide the height attribute into ranges as follows : \{0, 1.6\], (1.6, 1.7\], (1.7, 1.8\], (1.8, 1.9\], (1.9, 2.0\], (2.0, 5.0\] | Gender | Height (m) | Class | |:---:|:---:|:---:| | F | 1.6 | Short | | M | 2 | Tall | | F | 1.9 | Medium | | F | 1.88 | Medium | | F | 1.7 | Short | | M | 1.85 | Medium | | F | 1.6 | Short | | M | 1.7 | Short | | M | 2.2 | Tall | | M | 2.1 | Tall | | F | 1.8 | Medium | | M | 1.95 | Medium | | F | 1.9 | Medium | | F | 1.8 | Medium | | F | 1.75 | Medium |20218mMACHINE LEARNINGFor the Sun Burn data set given below, construct a decision tree. | Name | Hair | Height | Weight | Location | Class | |--------|--------|----------|---------|----------|-------| | Sunita | Blonde | Average | Light | No | Yes | | Anita | Blonde | Tall | Average | Yes | No | | Kavita | Brown | Short | Average | Yes | No | | Sushma | Blonde | Short | Average | No | Yes | | Xavier | Red | Average | Heavy | No | Yes | | Balaji | Brown | Tall | Heavy | No | No | | Ramesh | Brown | Average | Heavy | No | No | | Sweta | Blonde | Short | Light | Yes | No |202314mMACHINE LEARNINGApply the ID3 algorithm on the following data to draw a decision tree. Show the Information Gain at each split. ### Dataset | Outlook | Temperature | Humidity | Windy | PlayTennis | |-----------|-------------|----------|-------|-------------| | 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 | True | Yes | | Overcast | Mild | High | True | Yes | | Overcast | Hot | Normal | False | Yes | | Rainy | Mild | High | True | No |202510mData MiningDraw decision tree for the following data sets. Use entropy as a node selection mechanism: | Outlook | Temp (F) | Humidity | Windy | Class | |:---|:---|:---|:---|:---| | Rainy | Hot | High | False | No | | Rainy | Hot | High | True | No | | Overcast | Hot | High | False | Yes | | Sunny | Mild | High | False | Yes | | Sunny | Cool | Normal | False | Yes | | Sunny | Cool | Normal | True | No | | Overcast | Cool | Normal | True | Yes | | Rainy | Mild | High | False | No | | Rainy | Cool | Normal | False | Yes | | Sunny | Mild | Normal | False | Yes | | Rainy | Mild | Normal | True | Yes | | Overcast | Mild | High | True | Yes | | Overcast | Hot | Normal | False | Yes | | Sunny | Mild | High | True | No |202014m
Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.