All problems

Weighted Gini of a Split

mediumPythonDecision Trees

A rule in Ashby Mutual's rule-book takes one group of claims and divides it in two. That division is called a split, and each half becomes a group in its own right with its own mixture of outcomes. The modellers score a split by how mixed the two halves are left afterwards. The halves rarely hold the same number of claims, though, and a badly mixed half holding three claims should not weigh as heavily as a tidy half holding three hundred — so each half's Gini impurity counts in proportion to the share of the claims that landed in it. A lower score means a better split.

Task: Print the split's score.

Input

Three lines. The first holds k, the number of possible outcomes. The second holds the left half's k outcome counts, separated by single spaces. The third holds the right half's k counts, in the same outcome order. Both halves hold at least one claim, and between them they account for every claim in the original group.

Output

One line holding the split's score, written with exactly 4 digits after the decimal point.

Example:

Input:
2
30 10
10 40

Output:
0.3444

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…