← 返回 databricks 的题目列表Implement Linear Regression with Gradient Descent from Scratch
类型:online_judge
Problem: Implement Univariate Linear Regression Training with Gradient Descent
Given data points (x_i, y_i), train a univariate linear regression model using batch gradient descent:
[ \hat{y} = w x + b ]
Use mean squared error (MSE):
[ J(w,b) = \frac{1}{n}\sum_{i=1}^{n}(wx_i + b - y_i)^2 ]
Input
Line 1: n lr steps
Next n lines: x_i y_i as floats
Output
Print the final w and b separated by a space, to 6 decimal places.
Constraints
1 <= n <= 1e5
0 < lr <= 1
1 <= steps <= 1e5
Initialize w = 0, b = 0
Example
Input:
3 0.1 1000
1 2
2 4
3 6
Output (with tolerance):
2.000000 0.000000
Example
Input
3 0.1 1000
1 2
2 4
3 6
Output
2.000000 0.000000