Hunt's Algorithm Implementation in Python

Verified

Added on  2019/09/16

|1
|431
|174
Homework Assignment
AI Summary
This assignment requires the implementation of Hunt's algorithm for decision tree construction using Python. The task involves creating two primary functions: one to build a decision tree from a list of tuples, and another to predict the label for a given tuple using the constructed tree. The input data includes attribute types and integer-based tuples, with the label always being the last attribute. The tree structure is represented as nested tuples, and the algorithm follows a specific order for attribute selection. The assignment also includes testing the implementation with a converted example from a provided source.
Document Page
Assignment:
Write a python program to implement the Hunt’s algorithm for decision tree:
1. Function 1 to build a decision tree:
a. The input is a list of tuples:
i. The first tuple of this list is to describe the attribute type of the items in
the rest of the list. The attribute types could be ‘n’, ‘o’, ‘c’, and ’l’ for
nominal, ordinal, continuous, and label, respectively. Note that we
can assume the label attribute ‘l’ is always the last attribute in the
tuple, and it’s value is always either 0 or 1.
ii. The rest of the list is of fixed sized integer-tuples.
iii. For example, [(‘n’,’n’,’c’,’l’),(1,0,125,0), (0,2,100,0), …]
iv. Note that all the input values are of integer. For example, we can
convert our example in the ppt file, yes/no to be 1/0.
b. The output is a tree-like structure which could be a tuple of tuples as described
in the class. (left-child, information of current node, right-child). Please note
that null pointer is the keyword None in Python.
c. The choice of attribute for next node is in the same order of input attribute.
That is, root node is based on first attribute, and its child nodes are the
attribute 2.
d. Assume that each node can have at most two children.
e. We can assume the input list is legitimate. That is, we do not need to check
the quality of the input.
f. You might need to create more functions to be called to complete the tasks for
this function.
2. Function 2 returns a label (class) for a given tuple which is same structure (without
label) as the tuple in the list of the first function.
a. For example, the input could be (1,0,120) compared to the example of
function 1 above.
b. The output is either the label which is 0 or 1 for this assignment.
3. Create one example by converting our example from the ppt file, and test the results
with new tuples.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
[object Object]