Illustrate the working of Descision Tree Algorithm with the help of suitable example
Question
Illustrate the working of Descision Tree Algorithm with the help of suitable example
Solution
Sure, let's understand the working of the Decision Tree Algorithm with a simple example.
Suppose we have a dataset of weather conditions and we want to predict if a game can be played or not based on these conditions. The dataset is as follows:
| Outlook | Temperature | Humidity | Windy | 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 | True | Yes |
| Overcast | Mild | High | True | Yes |
| Overcast | Hot | Normal | False | Yes |
| Rainy | Mild | High | True | No |
Step 1: Calculate the entropy of the target.
Step 2: The dataset is then split on the different attributes. The entropy for each branch is calculated. Then it is added proportionally, to get total entropy for the split. The resulting entropy is subtracted from the entropy before the split. The result is the Information Gain, or decrease in entropy.
Step 3: Choose attribute with the largest information gain as the decision node, divide the dataset by its branches and repeat the same process on every branch.
Step 4: A branch with entropy of 0 is a leaf node.
Step 5: A branch with entropy more than 0 needs further splitting.
Step 6: The Decision Tree is built, and prediction is made with the help of this tree.
The decision tree for the above data will look something like this:
Outlook
|--- Sunny
| |--- Humidity
| | |--- High: No
| | |--- Normal: Yes
|--- Overcast: Yes
|--- Rainy
| |--- Windy
| | |--- False: Yes
| | |--- True: No
This tree can be used to predict whether a game can be played or not based on the weather conditions.
Similar Questions
- Provide a detailed algorithm for the Inorder tree traversal method. explain the answer for 5 marks
Problem statementYou are given a binary tree having nodes in string format.The boundary nodes of a binary tree include the nodes from the left and right boundaries and the leaf nodes, each node considered once.Figure out the boundary nodes of this binary tree in an Anti-Clockwise direction starting from the root node.Input format :List of numbers in string formatOutput format :Boundary nodes of a given binary treeSample test cases :Input 1 :3 4 5 6 7 8 9 10Output 1 :3 4 6 10 7 8 9 5
Consider the below codetakeInput() print("Enter root data") rootData = int(input()) if (rootData == -1) return None root = BinaryTreeNode(rootData) root.left = takeInput() root.right = takeInput() return rootWhat will be the input(excluding -1) to above code to construct this tree ? 1) 2 7 2 6 5 11 5 9 4 2) 2 7 5 6 11 2 5 4 9 3) 2 7 5 2 6 9 5 11 4
The first line contains an integer , the number of nodes in the tree.Next line contains space separated integer where th integer denotes node[i].data.
Level Order of TreeGiven an array of unique elements, construct a Binary Search Tree and print the Level Order of the tree.Input FormatFirst line of each test case contains N - number of nodes in the BST. The next line contains N unique integers - value of the nodes.ConstraintsPrint the Level Order of the Binary Search Tree, separate each level by newline.Output Format1 <= N <= 10000 <= ar[i] <= 10000Sample input6 10 5 15 2 7 12Sample output10 5 15 2 7 12
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.