This project showcases a Python solution for Assignment 3 of the CS 540 Introduction to Artificial Intelligence course at the University of Wisconsin-Madison, adapted from a CS 20551 Introduction to AI course at the Open University of Israel (2024a) as mmn (Matalat Manche
) 18. Originally based on Java code from the assignment, this reimplementation in Python achieved a perfect score! π―
The implementation of the decision tree is a testament to the robustness and versatility of Python, transitioning from Java while aiming to maintain the original code structure and interface integrity.
This module contains the formulas for the entropy and information gain calculations, providing a clear and concise representation of the underlying mathematics. The transition from Java to Python was seamless, with the code's readability and maintainability significantly improved.
Important formulas includes:
-
Entropy:
$H(S) = -\sum_{i=1}^{c} p_i \log_2 p_i$ where$p_i$ is the probability of class$i$ in the set$S$ . Thus, given binary classification,$H(S) = -p \log_2 p - (1-p) \log_2 (1-p)$ where$p$ is the probability of the positive class. The last formula is also written as$B(S)$ in some literature (e.g. the book "Artificial Intelligence: A Modern Approach" by Stuart Russell and Peter Norvig). -
Remainder:
$Remainder(S, A) = \sum_{v \in Values(A)} \frac{|S_v|}{|S|} H(S_v)$ where$S_v$ is the subset of$S$ for which attribute$A$ has value$v$ . -
Information Gain:
$IG(S, A) = H(S) - Remainder(S, A)$ gives the information gain of attribute$A$ on set$S$ .
At the core, this module encapsulates the essence of decision tree learning, adhering closely to the algorithms outlined in academic literature, with a sprinkle of personal insights for optimization. π€ The transition from Java's rigid type system to Python's dynamic nature posed challenges but ultimately led to a more flexible and readable codebase.
This script is the conductor of the symphony, ensuring each part of the decision tree's implementation plays together harmoniously. Through meticulous refactoring, the script now boasts enhanced clarity and structure, guiding the user through the process seamlessly.
A crucial component, this class ensures individual instances are managed efficiently, adopting a strategy that aligns with the data's inherent structure while providing easy access and manipulation capabilities.
These modules lay the groundwork for the decision tree's operation, translating complex Java logic into Pythonic elegance. The journey from static typing to dynamic required both creativity and precision, ensuring the algorithm's integrity remains intact.
Execute your decision tree adventure with the following command, substituting <F>
with your desired mode of operation:
python3 my_HW3.py <F> <train-set-file> <test-set-file>
Where <F>
represents one of the following modes:
-
mode 0
: Revel in the mutual information of each attribute at the root. -
mode 1
: Witness the birth of a decision tree from your training set. -
mode 2
: Predict the future of your test set with your tree. -
mode 3
: Validate your tree's wisdom against the test set. -
mode 4
: Generate a GIF of your tree's growth.
Dive into the examples to see the decision tree tackle real-world datasets, from tennis matches to loan approvals, demonstrating its versatility and accuracy across diverse scenarios.
The following output are from the tennis data set (Tennis.txt
), taken from p.222 of the studing material.
Note the Attributes are:
- A1: Outlook
- A2: Temperature
- A3: Humidity
- A4: Wind
- Label: Play
The train and test files are identical, so the accuracy is 1.0 as expected.
// tennis.txt
%%,Yes,No
##,A1,Sunny,Overcast,Rain
##,A2,Hot,Mild,Cool
##,A3,High,Normal
##,A4,Weak,Strong
Sunny,Hot,High,Weak,No
Sunny,Hot,High,Strong,No
Overcast,Hot,High,Weak,Yes
Rain,Mild,High,Weak,Yes
Rain,Cool,Normal,Weak,Yes
Rain,Cool,Normal,Strong,No
Overcast,Cool,Normal,Strong,Yes
Sunny,Mild,High,Weak,No
Sunny,Cool,Normal,Weak,Yes
Rain,Mild,Normal,Weak,Yes
Sunny,Mild,Normal,Strong,Yes
Overcast,Mild,High,Strong,Yes
Overcast,Hot,Normal,Weak,Yes
Rain,Mild,High,Strong,No
Outout of the program - matching the expected results from p.223:
dorpascal@Mac-mini HW3_Skeleton % python3.11 my_HW3.py 0 tennis.txt tennis.txt
A1 0.24675
A2 0.02922
A3 0.15184
A4 0.04813
dorpascal@Mac-mini HW3_Skeleton % python3.11 my_HW3.py 1 tennis.txt tennis.txt
βββ [A1=?]
β Sunny
βββ [A3=?]
β β High
β βββ Label: No
β β Normal
β βββ Label: Yes
β Overcast
βββ Label: Yes
β Rain
βββ [A4=?]
β Weak
βββ Label: Yes
β Strong
βββ Label: No
dorpascal@Mac-mini HW3_Skeleton % python3.11 my_HW3.py 2 tennis.txt tennis.txt
Classification of Instance: label=No, attributes=0, 0, 0, 0 = No - Correct? True
Classification of Instance: label=No, attributes=0, 0, 0, 1 = No - Correct? True
Classification of Instance: label=Yes, attributes=1, 0, 0, 0 = Yes - Correct? True
Classification of Instance: label=Yes, attributes=2, 1, 0, 0 = Yes - Correct? True
Classification of Instance: label=Yes, attributes=2, 2, 1, 0 = Yes - Correct? True
Classification of Instance: label=No, attributes=2, 2, 1, 1 = No - Correct? True
Classification of Instance: label=Yes, attributes=1, 2, 1, 1 = Yes - Correct? True
Classification of Instance: label=No, attributes=0, 1, 0, 0 = No - Correct? True
Classification of Instance: label=Yes, attributes=0, 2, 1, 0 = Yes - Correct? True
Classification of Instance: label=Yes, attributes=2, 1, 1, 0 = Yes - Correct? True
Classification of Instance: label=Yes, attributes=0, 1, 1, 1 = Yes - Correct? True
Classification of Instance: label=Yes, attributes=1, 1, 0, 1 = Yes - Correct? True
Classification of Instance: label=Yes, attributes=1, 0, 1, 0 = Yes - Correct? True
Classification of Instance: label=No, attributes=2, 1, 0, 1 = No - Correct? True
dorpascal@Mac-mini HW3_Skeleton % python3.11 my_HW3.py 3 tennis.txt tennis.txt
1.00000
GIF based on 108 instances for readability
The following output are from the loan application data set (prune_train.txt
and prune_test.txt
). Note that the name of the files probably should be loan_train.txt
and loan_test.txt
as the data set is about loans, but I kept the original names.
dorpascal@Mac-mini HW3_Skeleton % python3 my_HW3.py 0 prune_train.txt prune_test.txt
A1 0.08282
A2 0.03319
A3 0.06140
A4 0.01948
A5 0.00907
A6 0.02554
A7 0.00004
A8 0.00303
A9 0.00000
A10 0.00496
dorpascal@Mac-mini HW3_Skeleton % python3 my_HW3.py 1 prune_train.txt prune_test.txt
βββ [A1=?]
β x
βββ [A3=?]
β β a
β βββ [A5=?]
β β β h
β β βββ Label: B
β β β s
β β βββ Label: G
β β β u
β β βββ Label: G
β β c
β βββ [A2=?]
β β β n
β β βββ [A5=?]
β β β β h
β β β βββ [A4=?]
β β β β β o
β β β β βββ Label: G
β β β β β f
β β β β βββ Label: B
β β β β s
β β β βββ Label: G
β β β β u
β β β βββ [A4=?]
β β β β r
β β β βββ Label: G
β β β β o
β β β βββ Label: B
β β β b
β β βββ [A6=?]
β β β β c
β β β βββ [A5=?]
β β β β β h
β β β β βββ [A8=?]
β β β β β β 1
β β β β β βββ Label: G
β β β β β β 2
β β β β β βββ [A9=?]
β β β β β β y
β β β β β βββ [A4=?]
β β β β β β β o
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: G
β β β β β β n
β β β β β βββ Label: G
β β β β β s
β β β β βββ Label: G
β β β β β u
β β β β βββ Label: G
β β β β l
β β β βββ [A4=?]
β β β β β r
β β β β βββ Label: B
β β β β β o
β β β β βββ [A5=?]
β β β β β s
β β β β βββ [A9=?]
β β β β β β y
β β β β β βββ Label: G
β β β β β β n
β β β β β βββ [A7=?]
β β β β β β 1
β β β β β βββ [A8=?]
β β β β β β 2
β β β β β βββ [A10=?]
β β β β β β y
β β β β β βββ Label: G
β β β β β n
β β β β βββ Label: G
β β β β β u
β β β β βββ Label: G
β β β β r
β β β βββ Label: G
β β β β n
β β β βββ Label: G
β β β m
β β βββ [A6=?]
β β β β c
β β β βββ Label: G
β β β β l
β β β βββ Label: G
β β β β r
β β β βββ [A8=?]
β β β β 1
β β β βββ Label: G
β β β β 2
β β β βββ Label: B
β β β β 3
β β β βββ Label: G
β β β g
β β βββ Label: G
β β β w
β β βββ Label: G
β β d
β βββ [A7=?]
β β β 1
β β βββ [A5=?]
β β β β h
β β β βββ Label: B
β β β β s
β β β βββ Label: G
β β β β u
β β β βββ Label: G
β β β 2
β β βββ [A2=?]
β β β n
β β βββ Label: G
β β β b
β β βββ Label: B
β β β g
β β βββ Label: B
β β β w
β β βββ Label: B
β β e
β βββ [A8=?]
β β β 1
β β βββ [A2=?]
β β β β n
β β β βββ [A9=?]
β β β β β y
β β β β βββ Label: G
β β β β β n
β β β β βββ [A6=?]
β β β β β c
β β β β βββ Label: G
β β β β β l
β β β β βββ [A5=?]
β β β β β β s
β β β β β βββ Label: G
β β β β β β u
β β β β β βββ [A10=?]
β β β β β β y
β β β β β βββ Label: B
β β β β β β n
β β β β β βββ Label: G
β β β β β r
β β β β βββ [A5=?]
β β β β β β s
β β β β β βββ [A4=?]
β β β β β β β o
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: B
β β β β β β u
β β β β β βββ Label: G
β β β β β n
β β β β βββ Label: G
β β β β b
β β β βββ [A4=?]
β β β β β r
β β β β βββ [A5=?]
β β β β β β h
β β β β β βββ [A6=?]
β β β β β β β c
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A9=?]
β β β β β β β y
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: B
β β β β β β s
β β β β β βββ [A6=?]
β β β β β β β l
β β β β β β βββ Label: G
β β β β β β β r
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A9=?]
β β β β β β β n
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: B
β β β β β β u
β β β β β βββ Label: G
β β β β β o
β β β β βββ [A5=?]
β β β β β β h
β β β β β βββ Label: G
β β β β β β s
β β β β β βββ [A6=?]
β β β β β β β c
β β β β β β βββ Label: G
β β β β β β β l
β β β β β β βββ Label: G
β β β β β β β r
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A9=?]
β β β β β β β β y
β β β β β β β βββ Label: G
β β β β β β β β n
β β β β β β β βββ [A10=?]
β β β β β β β β y
β β β β β β β βββ Label: G
β β β β β β β 2
β β β β β β βββ Label: G
β β β β β β u
β β β β β βββ [A6=?]
β β β β β β l
β β β β β βββ Label: B
β β β β β β r
β β β β β βββ Label: G
β β β β β f
β β β β βββ Label: B
β β β β m
β β β βββ [A5=?]
β β β β β h
β β β β βββ [A4=?]
β β β β β β r
β β β β β βββ Label: G
β β β β β β o
β β β β β βββ Label: B
β β β β β s
β β β β βββ Label: G
β β β β β u
β β β β βββ Label: G
β β β β g
β β β βββ Label: G
β β β β w
β β β βββ Label: G
β β β 2
β β βββ [A2=?]
β β β β n
β β β βββ [A4=?]
β β β β β r
β β β β βββ Label: B
β β β β β o
β β β β βββ [A9=?]
β β β β β y
β β β β βββ Label: B
β β β β β n
β β β β βββ Label: G
β β β β b
β β β βββ [A6=?]
β β β β β c
β β β β βββ [A5=?]
β β β β β β h
β β β β β βββ [A4=?]
β β β β β β β r
β β β β β β βββ Label: G
β β β β β β β o
β β β β β β βββ Label: B
β β β β β β s
β β β β β βββ [A4=?]
β β β β β β β r
β β β β β β βββ Label: B
β β β β β β β o
β β β β β β βββ Label: G
β β β β β β u
β β β β β βββ Label: G
β β β β β r
β β β β βββ Label: G
β β β β β n
β β β β βββ Label: G
β β β β m
β β β βββ Label: B
β β β 3
β β βββ Label: G
β β n
β βββ [A2=?]
β β n
β βββ Label: B
β β b
β βββ [A7=?]
β β β 1
β β βββ Label: G
β β β 2
β β βββ Label: B
β β m
β βββ Label: G
β n
βββ [A3=?]
β β a
β βββ [A6=?]
β β β c
β β βββ [A2=?]
β β β β b
β β β βββ [A4=?]
β β β β β r
β β β β βββ Label: G
β β β β β o
β β β β βββ [A5=?]
β β β β β s
β β β β βββ Label: B
β β β β β u
β β β β βββ Label: G
β β β β m
β β β βββ Label: G
β β β l
β β βββ Label: B
β β β n
β β βββ Label: B
β β c
β βββ [A5=?]
β β β h
β β βββ Label: G
β β β s
β β βββ [A4=?]
β β β β r
β β β βββ Label: G
β β β β o
β β β βββ [A2=?]
β β β β β n
β β β β βββ Label: G
β β β β β b
β β β β βββ [A7=?]
β β β β β β 1
β β β β β βββ [A6=?]
β β β β β β β c
β β β β β β βββ [A8=?]
β β β β β β β β 2
β β β β β β β βββ [A9=?]
β β β β β β β β y
β β β β β β β βββ [A10=?]
β β β β β β β β y
β β β β β β β βββ Label: B
β β β β β β β l
β β β β β β βββ [A9=?]
β β β β β β β y
β β β β β β βββ Label: G
β β β β β β β n
β β β β β β βββ [A8=?]
β β β β β β β 2
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: B
β β β β β β 2
β β β β β βββ Label: G
β β β β β g
β β β β βββ Label: G
β β β β f
β β β βββ Label: B
β β β n
β β βββ Label: B
β β β u
β β βββ Label: G
β β d
β βββ [A2=?]
β β β n
β β βββ Label: G
β β β b
β β βββ Label: B
β β e
β βββ [A5=?]
β β β h
β β βββ [A6=?]
β β β β c
β β β βββ Label: G
β β β β l
β β β βββ [A2=?]
β β β β β n
β β β β βββ Label: G
β β β β β b
β β β β βββ [A4=?]
β β β β β r
β β β β βββ [A7=?]
β β β β β β 1
β β β β β βββ [A8=?]
β β β β β β 1
β β β β β βββ [A9=?]
β β β β β β y
β β β β β βββ [A10=?]
β β β β β β y
β β β β β βββ Label: B
β β β β β o
β β β β βββ Label: B
β β β β r
β β β βββ Label: G
β β β β n
β β β βββ [A2=?]
β β β β b
β β β βββ [A4=?]
β β β β f
β β β βββ [A7=?]
β β β β 1
β β β βββ [A8=?]
β β β β 1
β β β βββ [A9=?]
β β β β y
β β β βββ [A10=?]
β β β β y
β β β βββ Label: B
β β β s
β β βββ [A2=?]
β β β β n
β β β βββ [A9=?]
β β β β β y
β β β β βββ [A4=?]
β β β β β β r
β β β β β βββ Label: G
β β β β β β o
β β β β β βββ Label: G
β β β β β β f
β β β β β βββ Label: B
β β β β β n
β β β β βββ Label: B
β β β β b
β β β βββ [A8=?]
β β β β β 1
β β β β βββ [A9=?]
β β β β β β y
β β β β β βββ [A6=?]
β β β β β β β c
β β β β β β βββ Label: B
β β β β β β β l
β β β β β β βββ [A4=?]
β β β β β β β β o
β β β β β β β βββ [A7=?]
β β β β β β β β 1
β β β β β β β βββ [A10=?]
β β β β β β β β y
β β β β β β β βββ Label: B
β β β β β β β r
β β β β β β βββ Label: B
β β β β β β β n
β β β β β β βββ Label: B
β β β β β β n
β β β β β βββ [A6=?]
β β β β β β c
β β β β β βββ [A4=?]
β β β β β β β r
β β β β β β βββ Label: G
β β β β β β β o
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: G
β β β β β β l
β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A4=?]
β β β β β β β β r
β β β β β β β βββ [A10=?]
β β β β β β β β β y
β β β β β β β β βββ Label: B
β β β β β β β β o
β β β β β β β βββ Label: B
β β β β β β β 2
β β β β β β βββ [A4=?]
β β β β β β β o
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: G
β β β β β β r
β β β β β βββ [A4=?]
β β β β β β β r
β β β β β β βββ Label: B
β β β β β β β o
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ [A7=?]
β β β β β β β β 1
β β β β β β β βββ Label: B
β β β β β β β n
β β β β β β βββ Label: G
β β β β β β n
β β β β β βββ [A7=?]
β β β β β β 1
β β β β β βββ Label: G
β β β β β β 2
β β β β β βββ [A4=?]
β β β β β β f
β β β β β βββ [A10=?]
β β β β β β y
β β β β β βββ Label: B
β β β β β 2
β β β β βββ Label: B
β β β β m
β β β βββ Label: B
β β β β g
β β β βββ Label: G
β β β β w
β β β βββ Label: G
β β β n
β β βββ Label: G
β β β u
β β βββ [A6=?]
β β β c
β β βββ [A2=?]
β β β β b
β β β βββ Label: G
β β β β m
β β β βββ [A7=?]
β β β β 1
β β β βββ Label: B
β β β β 2
β β β βββ Label: G
β β β l
β β βββ Label: G
β β β r
β β βββ [A9=?]
β β β β y
β β β βββ Label: G
β β β β n
β β β βββ [A2=?]
β β β β n
β β β βββ Label: G
β β β β b
β β β βββ [A4=?]
β β β β r
β β β βββ Label: G
β β β β o
β β β βββ [A7=?]
β β β β 1
β β β βββ [A8=?]
β β β β β 1
β β β β βββ [A10=?]
β β β β β y
β β β β βββ Label: B
β β β β 2
β β β βββ Label: B
β β β n
β β βββ Label: B
β β n
β βββ [A6=?]
β β c
β βββ [A2=?]
β β β n
β β βββ Label: G
β β β b
β β βββ Label: B
β β l
β βββ Label: B
β β r
β βββ Label: G
β β n
β βββ Label: B
β b
βββ [A6=?]
β β c
β βββ [A2=?]
β β β n
β β βββ Label: G
β β β b
β β βββ [A4=?]
β β β β r
β β β βββ [A8=?]
β β β β β 1
β β β β βββ Label: G
β β β β β 2
β β β β βββ Label: B
β β β β β 3
β β β β βββ Label: G
β β β β o
β β β βββ [A3=?]
β β β β β c
β β β β βββ [A5=?]
β β β β β β h
β β β β β βββ Label: B
β β β β β β s
β β β β β βββ [A8=?]
β β β β β β 1
β β β β β βββ Label: B
β β β β β β 2
β β β β β βββ Label: G
β β β β β d
β β β β βββ Label: G
β β β β β e
β β β β βββ [A8=?]
β β β β β 1
β β β β βββ [A9=?]
β β β β β β y
β β β β β βββ [A5=?]
β β β β β β β s
β β β β β β βββ [A7=?]
β β β β β β β β 1
β β β β β β β βββ [A10=?]
β β β β β β β β β y
β β β β β β β β βββ Label: B
β β β β β β β β 2
β β β β β β β βββ Label: B
β β β β β β β u
β β β β β β βββ Label: B
β β β β β β n
β β β β β βββ [A10=?]
β β β β β β y
β β β β β βββ [A5=?]
β β β β β β β s
β β β β β β βββ Label: G
β β β β β β β u
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ Label: B
β β β β β β n
β β β β β βββ Label: B
β β β β β 2
β β β β βββ Label: G
β β β β f
β β β βββ Label: G
β β β m
β β βββ [A3=?]
β β β β a
β β β βββ Label: G
β β β β c
β β β βββ Label: G
β β β β d
β β β βββ [A5=?]
β β β β β h
β β β β βββ Label: B
β β β β β s
β β β β βββ Label: G
β β β β e
β β β βββ [A4=?]
β β β β β r
β β β β βββ Label: B
β β β β β o
β β β β βββ [A8=?]
β β β β β 1
β β β β βββ Label: B
β β β β β 2
β β β β βββ Label: G
β β β β n
β β β βββ Label: B
β β β g
β β βββ [A3=?]
β β β β c
β β β βββ Label: G
β β β β e
β β β βββ Label: B
β β β w
β β βββ Label: G
β β l
β βββ [A8=?]
β β β 1
β β βββ [A5=?]
β β β β h
β β β βββ Label: B
β β β β s
β β β βββ [A2=?]
β β β β β n
β β β β βββ [A3=?]
β β β β β β e
β β β β β βββ [A4=?]
β β β β β β o
β β β β β βββ [A7=?]
β β β β β β 1
β β β β β βββ [A9=?]
β β β β β β n
β β β β β βββ [A10=?]
β β β β β β y
β β β β β βββ Label: G
β β β β β b
β β β β βββ [A3=?]
β β β β β β c
β β β β β βββ [A4=?]
β β β β β β β o
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A9=?]
β β β β β β β n
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: B
β β β β β β d
β β β β β βββ Label: G
β β β β β β e
β β β β β βββ [A9=?]
β β β β β β y
β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ Label: B
β β β β β β β 2
β β β β β β βββ Label: G
β β β β β β n
β β β β β βββ Label: G
β β β β β m
β β β β βββ Label: B
β β β β n
β β β βββ Label: B
β β β β u
β β β βββ [A2=?]
β β β β n
β β β βββ Label: G
β β β β b
β β β βββ Label: B
β β β β m
β β β βββ Label: B
β β β β w
β β β βββ Label: G
β β β 2
β β βββ Label: G
β β r
β βββ [A8=?]
β β β 1
β β βββ [A2=?]
β β β β n
β β β βββ [A5=?]
β β β β β h
β β β β βββ Label: G
β β β β β s
β β β β βββ Label: B
β β β β b
β β β βββ [A4=?]
β β β β β r
β β β β βββ [A5=?]
β β β β β β h
β β β β β βββ Label: G
β β β β β β s
β β β β β βββ [A3=?]
β β β β β β β e
β β β β β β βββ [A7=?]
β β β β β β β 1
β β β β β β βββ [A9=?]
β β β β β β β n
β β β β β β βββ [A10=?]
β β β β β β β y
β β β β β β βββ Label: B
β β β β β β u
β β β β β βββ Label: G
β β β β β o
β β β β βββ Label: G
β β β β m
β β β βββ Label: G
β β β β g
β β β βββ [A5=?]
β β β β β s
β β β β βββ Label: G
β β β β β u
β β β β βββ [A3=?]
β β β β β e
β β β β βββ [A4=?]
β β β β β o
β β β β βββ [A7=?]
β β β β β 1
β β β β βββ [A9=?]
β β β β β n
β β β β βββ [A10=?]
β β β β β y
β β β β βββ Label: B
β β β β w
β β β βββ Label: G
β β β 2
β β βββ [A5=?]
β β β β h
β β β βββ Label: B
β β β β s
β β β βββ [A3=?]
β β β β β c
β β β β βββ [A2=?]
β β β β β β n
β β β β β βββ Label: G
β β β β β β b
β β β β β βββ Label: B
β β β β β d
β β β β βββ Label: G
β β β β β e
β β β β βββ Label: B
β β β β u
β β β βββ [A7=?]
β β β β 1
β β β βββ [A3=?]
β β β β β c
β β β β βββ [A2=?]
β β β β β β b
β β β β β βββ [A4=?]
β β β β β β o
β β β β β βββ [A9=?]
β β β β β β n
β β β β β βββ [A10=?]
β β β β β β y
β β β β β βββ Label: B
β β β β β e
β β β β βββ Label: G
β β β β 2
β β β βββ Label: G
β β β 3
β β βββ [A2=?]
β β β n
β β βββ Label: G
β β β b
β β βββ Label: B
β β n
β βββ [A3=?]
β β a
β βββ [A2=?]
β β β n
β β βββ Label: G
β β β b
β β βββ Label: B
β β β m
β β βββ Label: B
β β c
β βββ Label: G
β β d
β βββ [A2=?]
β β β b
β β βββ Label: B
β β β m
β β βββ [A4=?]
β β β o
β β βββ Label: B
β β β f
β β βββ Label: G
β β e
β βββ [A4=?]
β β β r
β β βββ Label: B
β β β o
β β βββ Label: B
β β β f
β β βββ [A5=?]
β β β h
β β βββ [A2=?]
β β β β b
β β β βββ [A7=?]
β β β β 1
β β β βββ [A8=?]
β β β β 1
β β β βββ [A9=?]
β β β β y
β β β βββ [A10=?]
β β β β y
β β β βββ Label: B
β β β s
β β βββ [A2=?]
β β β β n
β β β βββ [A7=?]
β β β β β 1
β β β β βββ [A8=?]
β β β β β 1
β β β β βββ [A9=?]
β β β β β y
β β β β βββ [A10=?]
β β β β β y
β β β β βββ Label: B
β β β β m
β β β βββ [A7=?]
β β β β 1
β β β βββ [A8=?]
β β β β 1
β β β βββ [A9=?]
β β β β n
β β β βββ [A10=?]
β β β β y
β β β βββ Label: B
β β β n
β β βββ Label: G
β β n
β βββ Label: B
β g
βββ [A3=?]
β a
βββ [A2=?]
β β n
β βββ Label: G
β β b
β βββ Label: B
β β w
β βββ Label: G
β c
βββ [A4=?]
β β r
β βββ Label: B
β β o
β βββ Label: G
β β f
β βββ Label: G
β d
βββ Label: B
β e
βββ Label: G
β n
βββ Label: G
dorpascal@Mac-mini HW3_Skeleton % python3 my_HW3.py 2 prune_train.txt prune_test.txt
Classification of Instance: label=B, attributes=1, 1, 2, 2, 1, 3, 1, 1, 1, 0 = B - Correct? True
Classification of Instance: label=B, attributes=1, 1, 0, 1, 1, 0, 0, 1, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 2, 0, 0, 0, 1 = G - Correct? True
Classification of Instance: label=G, attributes=3, 1, 3, 1, 3, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 3, 2, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 2, 1, 1, 1, 1, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=3, 1, 3, 0, 3, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 3, 1, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 2, 1, 1, 0, 1, 1, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=1, 1, 3, 0, 1, 0, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=B, attributes=1, 1, 1, 2, 3, 3, 0, 1, 1, 0 = G - Correct? False
Classification of Instance: label=B, attributes=2, 2, 0, 2, 0, 3, 0, 1, 0, 0 = B - Correct? True
Classification of Instance: label=B, attributes=1, 0, 3, 1, 1, 0, 0, 0, 1, 0 = B - Correct? True
Classification of Instance: label=G, attributes=3, 1, 2, 1, 1, 0, 0, 1, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=2, 1, 3, 2, 1, 3, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=B, attributes=1, 1, 3, 0, 1, 0, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 2, 0, 3, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 0, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=0, 1, 2, 1, 1, 0, 0, 1, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 0, 3, 1, 1, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 4, 1, 1, 2, 0, 1, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 0, 3, 1, 0, 1, 1, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 1, 3, 1, 1, 2, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 0, 1, 1, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 3, 1, 3, 0, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=1, 1, 3, 2, 1, 1, 1, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=3, 1, 3, 1, 1, 1, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 1, 1, 3, 0, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=1, 1, 1, 2, 0, 3, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 3, 1, 1, 1, 0, 0, 1, 0 = B - Correct? True
Classification of Instance: label=G, attributes=3, 1, 1, 1, 1, 1, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 2, 3, 1, 1, 2, 1, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 0, 1, 1, 1, 1, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=3, 0, 1, 0, 1, 3, 0, 1, 1, 0 = B - Correct? False
Classification of Instance: label=G, attributes=1, 1, 2, 1, 3, 1, 0, 1, 1, 0 = B - Correct? False
Classification of Instance: label=B, attributes=0, 3, 1, 2, 1, 3, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=2, 1, 3, 1, 0, 3, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=1, 1, 3, 1, 3, 0, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=B, attributes=1, 1, 2, 1, 1, 3, 0, 1, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=1, 4, 3, 1, 1, 1, 1, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 3, 2, 1, 3, 1, 2, 0, 0 = G - Correct? False
Classification of Instance: label=B, attributes=0, 1, 3, 1, 0, 0, 0, 0, 0, 0 = G - Correct? False
Classification of Instance: label=B, attributes=2, 4, 1, 2, 1, 3, 1, 1, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=1, 1, 3, 1, 1, 3, 1, 0, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=1, 1, 1, 0, 1, 2, 0, 2, 0, 0 = G - Correct? False
Classification of Instance: label=B, attributes=1, 1, 1, 0, 1, 1, 0, 0, 0, 0 = G - Correct? False
Classification of Instance: label=B, attributes=2, 0, 3, 1, 1, 1, 0, 0, 0, 0 = G - Correct? False
Classification of Instance: label=B, attributes=2, 1, 4, 2, 0, 3, 0, 0, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 2, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 3, 3, 1, 1, 1, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 3, 3, 1, 1, 1, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 0, 3, 0, 1, 2, 0, 0, 1, 0 = B - Correct? False
Classification of Instance: label=G, attributes=1, 1, 3, 1, 0, 1, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=G, attributes=2, 3, 1, 1, 0, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 3, 0, 1, 3, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=1, 1, 3, 1, 3, 1, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 0, 2, 0, 3, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=G, attributes=1, 1, 1, 0, 1, 2, 1, 1, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 4, 0, 1, 3, 1, 1, 1, 0 = B - Correct? True
Classification of Instance: label=B, attributes=1, 1, 3, 2, 1, 3, 0, 0, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 2, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 2, 3, 1, 1, 0, 0, 0, 1, 0 = B - Correct? False
Classification of Instance: label=B, attributes=1, 1, 3, 2, 0, 3, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 2, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 2, 3, 1, 1, 0, 0, 1, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=2, 2, 1, 1, 1, 3, 1, 1, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 0, 1, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=0, 1, 3, 1, 3, 0, 1, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 2, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 1, 1, 1, 0, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 4, 1, 1, 1, 0, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 1, 1, 1, 2, 0, 1, 1, 0 = B - Correct? True
Classification of Instance: label=G, attributes=3, 1, 2, 1, 1, 1, 0, 0, 1, 0 = B - Correct? False
Classification of Instance: label=B, attributes=1, 0, 3, 1, 1, 0, 0, 0, 1, 0 = B - Correct? True
Classification of Instance: label=G, attributes=0, 3, 3, 1, 0, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 0, 2, 3, 3, 0, 0, 1, 0 = B - Correct? True
Classification of Instance: label=G, attributes=2, 4, 3, 1, 1, 2, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 1, 3, 2, 1, 0, 1, 1 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 3, 2, 0, 3, 0, 0, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=1, 3, 3, 1, 1, 2, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 2, 2, 1, 3, 1, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 1, 3, 2, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 3, 1, 1, 1, 1, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 0, 1, 1, 1, 0, 0, 1, 1, 1 = G - Correct? True
Classification of Instance: label=G, attributes=2, 4, 1, 1, 1, 0, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 3, 0, 2, 1, 3, 1, 0, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=0, 4, 3, 1, 1, 2, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=3, 0, 3, 1, 0, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 3, 4, 1, 1, 0, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 1, 2, 0, 1, 1, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 1, 0, 1, 1, 0, 1, 1, 1 = G - Correct? False
Classification of Instance: label=B, attributes=2, 1, 3, 1, 1, 2, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=1, 0, 3, 0, 3, 0, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 4, 1, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 0, 1, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 0, 2, 2, 1, 3, 1, 0, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=3, 1, 4, 1, 0, 0, 0, 1, 0, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 1, 1, 1, 0, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 2, 0, 1, 2, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 0, 1, 1, 1, 0, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=0, 1, 3, 1, 1, 1, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=2, 0, 1, 1, 1, 2, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 1, 3, 1, 0, 2, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 2, 3, 1, 1, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 3, 1, 3, 1, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 0, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 4, 1, 1, 0, 0, 0, 0, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 0, 3, 1, 0, 2, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 2, 1, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 2, 0, 3, 1, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 0, 3, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=0, 0, 0, 1, 0, 2, 0, 0, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=2, 0, 3, 1, 3, 1, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 0, 1, 1, 3, 2, 1, 1, 1, 0 = B - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 2, 2, 1, 3, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 2, 0, 3, 0, 2, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 3, 1, 1, 2, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=1, 1, 3, 2, 0, 3, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=1, 1, 0, 1, 1, 1, 0, 0, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=0, 1, 1, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 3, 1, 1, 3, 0, 0, 1, 0 = B - Correct? True
Classification of Instance: label=B, attributes=3, 2, 3, 2, 3, 3, 1, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 1, 1, 1, 1, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 2, 2, 0, 1, 1, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 1, 0, 0, 2, 0, 0, 0, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 1, 0, 0, 0, 1 = G - Correct? True
Classification of Instance: label=G, attributes=3, 1, 1, 2, 1, 3, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 0, 1, 1, 0, 1, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 0, 1, 2, 1, 2, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=1, 1, 3, 1, 1, 0, 0, 0, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=2, 0, 2, 2, 0, 3, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 1, 2, 1, 1, 0, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 1, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=2, 1, 3, 1, 1, 0, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 2, 2, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 3, 1, 0, 1, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=0, 1, 2, 1, 1, 2, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 0, 3, 1, 1, 1, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=B, attributes=0, 3, 3, 1, 1, 1, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 0, 2, 1, 1, 0, 1, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 1, 3, 1, 3, 2, 1, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 1, 1, 1, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 1, 1, 1, 3, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=B, attributes=0, 1, 3, 1, 1, 0, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=B, attributes=2, 1, 3, 1, 1, 1, 0, 0, 1, 0 = G - Correct? False
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 2, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 2, 2, 0, 0, 0, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=B, attributes=1, 1, 2, 1, 1, 0, 0, 1, 0, 0 = B - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 1, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 0, 3, 1, 3, 1, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 0, 3, 1, 1, 0, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 0, 3, 2, 1, 3, 1, 0, 0, 0 = B - Correct? False
Classification of Instance: label=G, attributes=0, 1, 1, 1, 1, 2, 0, 1, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=2, 1, 3, 1, 1, 2, 0, 0, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 3, 2, 0, 3, 0, 0, 0, 0 = B - Correct? False
Classification of Instance: label=G, attributes=0, 0, 3, 0, 1, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 3, 1, 3, 2, 1, 0, 1, 1 = G - Correct? True
Classification of Instance: label=G, attributes=0, 1, 1, 1, 1, 3, 0, 1, 1, 0 = G - Correct? True
Classification of Instance: label=G, attributes=0, 0, 3, 1, 1, 0, 0, 0, 0, 0 = G - Correct? True
Classification of Instance: label=G, attributes=1, 1, 3, 1, 0, 0, 0, 0, 1, 0 = G - Correct? True
dorpascal@Mac-mini HW3_Skeleton % python3 my_HW3.py 3 prune_train.txt prune_test.txt
0.67485