Home Artificial Intelligence Why Decision Tree -Cart algorithm is true for you? Decision tree CART Algorithm 1. Gini Index 2.Information Gain

Why Decision Tree -Cart algorithm is true for you? Decision tree CART Algorithm 1. Gini Index 2.Information Gain

1
Why Decision Tree -Cart algorithm is true for you?
Decision tree
CART Algorithm
1. Gini Index
2.Information Gain

Credit:Decision tree |The Times of India (indiatimes.com)

Are you interested in how machines could make accurate predictions and decisions? Machine learning uses decision tree to make accurate predictions and decisions.CART is a strong technique inside machine learning that permits decision tree to efficiently train on large dataset.

A Decision tree (DT) is a tree-like graph to map decisions and their outcomes. It might probably be used for each categorization and regression. It has a hierarchical structure with nodes and edges, which help us to represent complex decision-making processes in a straightforward and comprehensible way.

In our each day lives, we regularly encounter several scenarios where we must answer a set of questionnaire sessions to finally get an answer. If we model the decision-making process as a choice tree, each query could be labelled as a node.

For instance, one candidate needs to make a decision whether to take the employment opportunity based on

1. The salary offered is $50,000 or above.

· Yes-accept.

2. travel hours greater than 1 hour

· Yes-reject.

3. provide any complimentary coffee

· Yes -accept.

Decision Tree Classifier, source:https://brookewenig.github.io

So, that is the fundamental idea of a choice tree, and using this method, we will predict the goal variable, which is why we call it as Decision Tree.

Within the above figure, each box is identified as a

The primary node is known as

The nodes in green are the results of the questionnaire. These nodes are called, which have the ultimate answers.

All the opposite intermediate nodes are called .

Decision tree Algorithm :

There are several algorithms to construct a choice tree,

1. CART-Classification and Regression Trees

2. ID3-Iterative Dichotomiser 3

3. C4.5

4. CHAID-Chi-squared Automatic Interaction Detection

5. MARS-Multivariate Adaptive Regression Splines

, as its name would imply. The excellence is between the variables. It’s a recursive binary partitioning technique that creates a DT by iteratively splitting the info into subsets depending on the values of a single input variable. It processes data directly (no preprocessing is crucial), allowing many instances of the identical variable for use in numerous areas of the identical DT.

For instance, the gathering comprises information on flowers’ sepal, petal, and ovary dimensions in addition to the related species (Iris setosa, Iris Versicolor, and Iris virginica).
If two features — petal and sepal width and length — and a dataset of 150 samples are employed, it should be simpler to grasp. Versicolor, Virginica, and Iris setosa, respectively, as species in dataset.

CART algorithms use the criterion and to find out the . While ,the opposite algorithm uses reduction in entropy. We at the moment are only discussing the CART algorithm, because it is essentially the most used.

It’s the measure of impurity or purity of a dataset and is used to guage the split of the dataset. It’s calculated by subtracting the sum of the squared probabilities of every class from one.

Mathematically,

Image by Writer

So, for our dataset

Gini index=0.66

Tree classifier. Image by Writer

The entire data set is represented by the basis node of the tree, which has 120 samples in it. The Gini index for this node is 0.66, which indicates that the info set is somewhat

If the feature is lower than 100, it is assessed as Iris setosa with a Gini value of zero as a consequence of no overlap. Nonetheless, whether it is 100 or more, there are still 78 samples to contemplate.

Within the left branch of the primary split,the Gini index is 0.499 with samples 78, while the opposite branch shows a Gini index of 0 as there isn’t any overlap. It is assessed as Iris setosa.

In the appropriate branch of the second split, the third split also uses the standards, but this time is assessed as either Iris virginica or Iris versicolor. These partitions are pure, with Gini values of 0 within the samples 41 and 37.

The tree divides the flowers into three groups: Iris setosa, Iris versicolor, and Iris virginica, based on their petal length.

The tree has three layers and 4 terminal nodes, each representing a category label. To create the tree, the split with the bottom Gini index at each level is chosen repeatedly. The Gini index measures the standard of every split. To categorise accurately, the tree’s complexity must increase together with the complexity of the dataset.

We can even split the info using Information gain. It’s the measure of data that a feature provides a few class or goal variable. Information gain is the difference between the impurity of the parent node and the weighted average impurity of the kid node. It decides which feature needs to be used to separate.

Information gain=Entropy-Average entropy

Image by Writer

Pk is the probability of sophistication k.

Entropy is the measure of the degree of randomness in the category distribution on the node.

Steps for CART Algorithm:

To start with, the required crucial libraries to be imported and in addition the datset called ‘Iris’.

Importing libraries and dataset -Iris. Image by Writer

Step 1. Understand the dataset and data preparation if needed.

Basic Summary about Iris dataset. Image by Writer

Step 2. Split the info into test and train data.

Image by Writer

Step 3. Select the independent and goal variables. It might probably be continous variable (regression problem) and categorical variable(classification) for goal variable.

Image by Writer

Step 4. Construct model using chosen criterion and an impurity measure to separate the info based on criterion.

Image by Writer

Step 5. Evaluate the model using accuracy, precision and f1 rating.

Image by Writer
tree classifier code

Also, plot the tree classifier graph and visualize the connection between variables.

Sepalwidth vs Petalwidth .Image by Writer

Why pruning?

Pruning is a method that reduces a tree’s size by removing irrelevant branches. This process will help minimize overfitting while optimizing its structure. Overfitting occurs when an advanced model captures noise or unrelated information from a training set.

There are two forms of pruning: pre-pruning and post-pruning. By specifying certain conditions (hyperparameters) comparable to maximum depth, and minimum samples per leaf. That is pre-pruning. Post-pruning is replacing nodes from the grown tree with leaves to cut back the complexity. Probably the most typical method of creating the branches simpler is that this one.

Pruning can significantly improve the accuracy and interpretability of the CART model by reducing complexity, improving performance, and highlighting features and essential relationships in the info.

: This parameter helps set the utmost variety of nodes(levels)in a choice tree. It will help reduce tree overfitting.

That is the minimum variety of samples that have to be required for splitting. If the variety of samples is lower than threshold, pruning is applied.

it’s the parameter defining the minimum variety of samples required in its internal node before its splits.

Benefits:

1., as it will possibly handle each categorical and numerical features.

2. to each because it is visualized.

3.Decision tree simply need basic computation, making training them

Limitations:

1.Decision trees could be liable to the training data in the event that they are complex.

2.It’s in data.

3.Tree structure could also be .

In conclusion, decision tree is an easy and a well-liked approach for classification and decision problems. It allows transparent decision-making by breaking down complex problems into simpler decision rules. Nonetheless, like every other machine learning algorithms, it has its own limitations and could be liable to bias and instability. To cut back these problems, it’s crucial to fastidiously select the model’s problems and to fine-tune it.

The writing relies on my studies and references.

References

Kumar, G.S., 2020. Decision trees: A step-by-step approach to constructing DTS. [online] Medium. Available at: [Accessed 13 Apr. 2023].

Reddy, E.P.K. (2022) Complete flow of decision tree algorithm, Analytics Vidhya. Available at: https://www.analyticsvidhya.com/blog/2022/04/complete-flow-of-decision-tree-algorithm/ (Accessed: April 13, 2023)

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here