← 返回 capitalone 的题目列表ML Coding: Implement Linear Regression (from scratch)
类型:online_judge
ML Coding: Implement Linear Regression (from scratch)
Implement training and inference for linear regression using batch gradient descent to minimize MSE:
[ \text{MSE}(w,b)=\frac{1}{n}\sum_{i=1}^{n}(\hat y_i-y_i)^2,\quad \hat y = Xw + b ]
Input (stdin)
First line: n d m iters
Second line: lr
Next n lines: d floats for X[i]
Next n lines: 1 float for y[i]
Next m lines: d floats for X_test[j]
Output (stdout)
Line 1: d floats for w
Line 2: float b
Next m lines: predictions
Constraints
1 <= n,m <= 2000, 1 <= d <= 50, iters <= 20000
Example
See test cases below.
Example
Input
4 2 2 2000
0.05
1 1
1 2
2 2
2 3
2
3
4
5
3 5
0 1
Output
(one possible)
1.0 1.0
0.0
8.0
1.0