All problems

Finding the Best Split Threshold

hardPythonDecision Trees

Ashby Mutual wants its first rule to key on a single number: the amount a claim was made for. A rule like that is a cut point — claims at or below the cut go left, everything above it goes right. The modellers have a shortlist of candidate cut points and want whichever leaves the two sides tidiest, scored exactly as a split was scored before: each side's Gini impurity counting in proportion to the claims that landed on that side, lower being better. A side that ends up with no claims at all contributes nothing to the score.

Task: Print the cut point that scores best.

Input

The first line holds n, the number of past claims. Each of the next n lines holds a claim's amount followed by its outcome, which is 0 or 1, separated by a space. The next line holds m, the number of candidate cut points, and the line after that holds those m values separated by single spaces.

Output

One line holding the winning cut point, written with exactly 1 digit after the decimal point. If two or more candidates score exactly the same, print whichever appeared earliest on the candidate line.

Example:

Input:
4
1 0
2 0
3 1
4 1
3
1.5 2.5 3.5

Output:
2.5

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…