All problems

The F1 Score

hardPythonML Metrics

Harborline's two managers quote different numbers at each other: the floor manager watches the hit rate on the flags, the compliance officer the catch rate on dangerous parcels. The board wants both, plus one combined score that cannot look good while either half is bad.

Task: Print the hit rate, the catch rate, and the combined score.

Input

The first line holds an integer n, the number of parcels. Each of the next n lines holds two values separated by a single space: the true label first, the model's label second. Both are 1 (banned item inside) or 0 (clean). At least one dangerous parcel was flagged, so all three numbers exist.

Output

Three lines in this order, each a label, one space, and a value with exactly two digits after the decimal point:

precision X.XX — the share of flagged parcels that were dangerous. recall X.XX — the share of dangerous parcels that were flagged. f1 X.XX — the harmonic mean of those two rates, which settles near the smaller of the pair instead of splitting the difference.

Example:

Input:
6
1 1
1 0
0 1
1 1
0 0
1 1

Output:
precision 0.75
recall 0.75
f1 0.75

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…