← 返回 apple 的题目列表Implement Stochastic Gradient Descent to Fit a Line
类型:online_judge
Implement a Stochastic Gradient Descent (SGD) algorithm to fit the line y = ax + b. Include backpropagation and formula derivation in the implementation. Test cases:
Input: data points [(1, 2), (2, 4), (3, 6)], Output: approximate a and b
Input: data points [(1, 3), (2, 5), (3, 7)], Output: approximate a and b
Input: data points [(0, 0), (1, 1)], Output: approximate a and b
Input: data points [(1, 1), (2, 3)], Output: approximate a and b
Input: data points [(1, 0), (0, 1)], Output: approximate a and b
Requirement: Provide implementation details and the definition of the error function. The number of data points can be more than in the test cases.
Example
Input
[(1, 2), (2, 4), (3, 6)]