Decision tree algorithm is a commonly used supervised learning algorithm, solves classification problems. Decision tree is the graphical representation of all the possible solutions to a decision. Decisions are based on some conditions.
Decision tree is a tree-like structure, that breaks down a dataset into smaller and smaller subsets. The final result is a tree with decision nodes and leaf nodes. The topmost decision node in a tree which corresponds to the best predictor called the root node.
The entire tree implements by answering “True/False” questions until it reaches the leaf node. Decision tree can handle both categorical and numerical data. They are extremely useful for data analytics and machine learning because they break down complex data into more manageable parts. They’re often used in these fields for prediction analysis, data classification, and regression.
Example of Decision tree Algorithm:
In the above example the root node checks whether the person is hungry. If the person is not hungry, then it goes to eat after sometime, else checks whether it is lunch time. If it is lunch time the person gets the food, else he will get after some time. The final eat node is the decision node.
Another example of Decision tree:
Implementation of Decision tree algorithm:
- Import the required libraries.
- Initialize and print the dataset.
- Fit decision tree to the dataset.
- Predicting the result with new value.
- Visualizing the result.
Advantages of Decision tree:
- Decision trees have an advantage that it is easy to understand.
- A decision tree does not require normalization of data.
- Data cleaning is required less.
Disadvantages of Decision tree:
- Decision tree often involves higher time to train the model.
- Adding a new-data point can lead to regeneration of all the over-all tree and all nodes need to be recalculated and recreated.