Splitting the Nodes
During training, we need to find the best split at each decision node. When we split the data into two nodes, we aim for different classes to be in separate nodes.
- Best case scenario: all data points in a node belong to the same class;
- Worst case scenario: an equal number of data points for each class.
Gini Impurity
To measure how good a split is, we can calculate the Gini impurity. It is the probability that if we randomly take two points from a node (with replacement), they will be of different classes. The lower this probability (impurity), the better the split.
You can calculate the Gini impurity for binary classification using the following formula:
gini=1−p02−p12=1−(mm0)2−(mm1)2Where
- mi - number of instances of class i in a node;
- m - number of instances in a node;
- pi=mmi - probability of choosing class i.
And for multiclass classification, the formula is:
gini=1−i=0∑Cpi2=1−i=0∑C(mmi)2Where
- C - number of classes.
We can measure how good the split is by taking the weighted sum of Gini scores for both nodes obtained from a split. That's the value we want to minimize.
To split a decision node, we need to find a feature to split on and the threshold:
At a decision node, the algorithm greedily finds the best threshold for each feature. Then it chooses the split with the lowest Gini impurity out of all features (if there is a tie, it chooses randomly).
Entropy
The entropy is another measure of the impurity. For a binary classification problem, the entropy H of a node is calculated using the formula:
H(p)=−plog2(p)−(1−p)log2(1−p)where:
- p is the proportion of positive examples (class 1);
- 1−p is the proportion of negative examples (class 0).
For a multiclass classification problem, the entropy H of a node is calculated using the formula:
H(p1,p2,…,pk)=−i=1∑kpilog2(pi)where:
- k is the number of classes;
- pi is the proportion of examples belonging to class i in the node.
Similarly to Gini impurity, we can measure how good a split is by calculating the weighted sum of entropy values for the child nodes obtained from the split. This is the value we want to minimize in order to maximize the information gain.
The entropy is maximum when all classes are equally represented. It is minimum (0) when all examples belong to one class (pure node).
Obrigado pelo seu feedback!
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Incrível!
Completion taxa melhorada para 5.88
Splitting the Nodes
Deslize para mostrar o menu
During training, we need to find the best split at each decision node. When we split the data into two nodes, we aim for different classes to be in separate nodes.
- Best case scenario: all data points in a node belong to the same class;
- Worst case scenario: an equal number of data points for each class.
Gini Impurity
To measure how good a split is, we can calculate the Gini impurity. It is the probability that if we randomly take two points from a node (with replacement), they will be of different classes. The lower this probability (impurity), the better the split.
You can calculate the Gini impurity for binary classification using the following formula:
gini=1−p02−p12=1−(mm0)2−(mm1)2Where
- mi - number of instances of class i in a node;
- m - number of instances in a node;
- pi=mmi - probability of choosing class i.
And for multiclass classification, the formula is:
gini=1−i=0∑Cpi2=1−i=0∑C(mmi)2Where
- C - number of classes.
We can measure how good the split is by taking the weighted sum of Gini scores for both nodes obtained from a split. That's the value we want to minimize.
To split a decision node, we need to find a feature to split on and the threshold:
At a decision node, the algorithm greedily finds the best threshold for each feature. Then it chooses the split with the lowest Gini impurity out of all features (if there is a tie, it chooses randomly).
Entropy
The entropy is another measure of the impurity. For a binary classification problem, the entropy H of a node is calculated using the formula:
H(p)=−plog2(p)−(1−p)log2(1−p)where:
- p is the proportion of positive examples (class 1);
- 1−p is the proportion of negative examples (class 0).
For a multiclass classification problem, the entropy H of a node is calculated using the formula:
H(p1,p2,…,pk)=−i=1∑kpilog2(pi)where:
- k is the number of classes;
- pi is the proportion of examples belonging to class i in the node.
Similarly to Gini impurity, we can measure how good a split is by calculating the weighted sum of entropy values for the child nodes obtained from the split. This is the value we want to minimize in order to maximize the information gain.
The entropy is maximum when all classes are equally represented. It is minimum (0) when all examples belong to one class (pure node).
Obrigado pelo seu feedback!