All problems

How Well Does the Line Fit?

mediumPythonRegression

Back to the Lantern Tutors pilot: a cohort of students, their hours on the practice app, and their marks out of 10, paired by position.

The owner is drafting a funding application that says app time "explains" quiz performance. The reviewer will ask her to back that word with a figure: of all the variation in marks across a cohort, what share does the fitted line actually account for? It should land between 0 and 1 - 1 if the line passes through every student exactly, 0 if it does no better than ignoring hours entirely and guessing the group's average mark for everybody. She wants the figure for each cohort she has run.

Task: Print the R-squared (coefficient of determination) for the least-squares line predicting marks from hours, rounded to 2 decimals.

Input

Two lines. The first holds the hours, one per student, separated by single spaces. The second holds the marks in the same order. Both lines hold the same number of entries, there are at least two, and neither list is entirely made of one repeated value.

Output

One line holding R-squared, rounded to 2 decimals and printed the way Python prints a float - 0.6, never 0.60 and never negative.

Example:

Input:
1 2 3 4 5
2 4 5 4 5

Output:
0.6

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…