All problems

Information Gain From a Split

hardPythonDecision Trees

Ashby Mutual scores a candidate rule by how much uncertainty it removes. Before the split there is one group of claims with a certain entropy — how much you still would not know about a claim drawn from it, in bits, so an even two-way mixture scores 1. After the split there are two halves, each with its own entropy, and each counting in proportion to the share of the group's claims that landed in it. A rule's information gain is how far that second figure falls short of the first: the bits of uncertainty the rule bought. A bigger gain means a better rule.

Task: Print the information gain of the split.

Input

Four lines. The first holds k, the number of possible outcomes. The second holds the group's k outcome counts before the split. The third holds the left half's k counts and the fourth the right half's — all in the same outcome order, separated by single spaces. The two halves between them account for exactly the claims in the group above, and neither half is empty.

Output

One line holding the information gain in bits, written with exactly 4 digits after the decimal point.

Example:

Input:
2
50 50
40 10
10 40

Output:
0.2781

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…