Gini Impurity vs Entropy: Weighted Split Comparison
Xem dạng PDF
Gửi bài giải
Điểm:
100,00
Giới hạn thời gian:
2.0s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python
Task
Given two child nodes of a binary split (each described by the count of positive examples and the total count), compute the weighted Gini impurity and weighted entropy for the split, then report their difference. Gini impurity for a node: 2p(1-p). Binary entropy for a node: -plog2(p) - (1-p)log2(1-p). The weighted value for the split is w1impurity(node1) + w2impurity(node2) where wi = Ni / (N1 + N2).
Input
- Line 1:
n1 N1 n2 N2— positive count and total count for the left node, positive count and total count for the right node
Output
Print three values each on its own line: weightedgini, weightedentropy, giniminusentropy — each with up to 10 significant digits.
Example
Input:
3 5 2 5
Output:
0.48
0.9709505945
-0.4909505945
Scaffolding
Submit a Python file defining:
def gini_entropy_split(n1: int, N1: int, n2: int, N2: int) -> tuple[float, float, float]:
...
Receives positive counts and totals for two child nodes; returns a tuple (weighted_gini, weighted_entropy, gini_minus_entropy).
Bình luận