All problems

A Scatter Plus Fit Line With regplot

easyPythonSeabornregplot

Calder Engineering loads a test beam by degrees and records how far it bends. The rig chart already shows the readings with a straight line drawn through them. What the sign-off sheet needs is the tilt of that line as a number: how much further the beam bends for each extra unit of load.

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

Input

The first line holds one integer n, the number of readings, where 2 <= n <= 1000. Then come n lines, each holding a reading's x and y separated by a single space, x first. Not every reading 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 readings, each squared first, add to the smallest total any line could manage -- and y is the quantity being predicted, x the one doing the predicting.

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…