Interview Query

Gradient Descent Calculation

0
Have you seen this question before?

You are given a set of (xx, yy) coordinates.

Write a function using gradient descent to return a tuple describing the line of best fit for the given coordinates. The first number in the tuple should be the line’s slope. The second number in the tuple should be its y-intercept.

Example:

Input:

coordinates = [(0, 1), (1, 3), (2, 2), (3, 4), (4, 6), (5, 5), (6, 7), (7, 9), (8, 8), (9, 10), (10, 12), (11, 11), (12, 13), (13, 15), (14, 14), (15, 16), (16, 18), (17, 17), (18, 19)]

Output:

(1, 1) 
Next question: Location Frequency
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code