All problems

Variance Explained

hardPythonML MetricsRegression

Northwind's data team is asked every quarter whether the forecasting model earns its licence fee. The fair comparison is not against perfection but against the laziest thing anyone could do: ignore every signal and quote the same average figure every day. The board wants one number for how much of the day-to-day movement in demand the model actually accounts for.

Task: Print the model's R² — the share of the variation in true demand that it explains.

Input

The first line holds an integer n, the number of days. Each of the next n lines holds two numbers separated by a single space: the true demand first, the forecast second.

Output

One line with exactly three digits after the decimal point. The lazy comparison is the average of the true demands across the batch. A model that matches the truth exactly prints 1.000; a model exactly as good as that average prints 0.000; a model worse than the average is allowed to go below zero, so do not clip the result.

Example:

Input:
5
1 1.2
2 1.9
3 3.1
4 4.2
5 4.8

Output:
0.986

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…