All problems

Adding Regression Lines With kind='reg'

hardPythonSeabornkind=reg

Thornbury Labs has narrowed a batch down to two measurements per sample, x and y, and now wants the relationship quantified rather than eyeballed. The panel already draws a straight line through the cloud of points. The report needs the tilt of that line: how much y moves when x goes up by one.

Task: Print the slope of the least-squares line predicting y from x.

Input

The first line holds one integer n, where 2 <= n <= 1000. Then come n lines, each holding a sample's x and y separated by a single space. Not every sample has the same x.

Output

One line holding the slope, rounded to 2 decimal places. The line is the least-squares one -- the single straight line for which the up-and-down gaps to the points, squared first, add to the smallest total possible -- and y is the measurement being predicted, x the predictor. Round only at printing time: a perfectly flat relationship can come out as -0.00, and that is the wanted text.

Example:

Input:
3
1 2
2 4
3 6

Output:
2.00

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…