← 返回 goldmansachs 的题目列表Implement Linear Regression Backpropagation and Training
类型:online_judge
Implement Linear Regression Backpropagation and Training
Given a training dataset, train a linear-regression model using full-batch gradient descent:
[ \hat y = Xw + b ]
where X is the feature matrix, w is the weight vector, and b is the bias. The loss is mean squared error:
[ L = \frac{1}{n}\sum_{i=1}^{n}(\hat y_i-y_i)^2 ]
Implement from scratch:
The forward pass;
Gradients for w and b;
Gradient-descent parameter updates;
Output the final parameters after the requested number of epochs.
Initialize all parameters to zero.
Input
First line: n d epochs lr
Next n lines: d feature values followed by target y.
Output
Print the final weights on the first line and the final bias on the second line. Print every floating-point value with 6 decimal places.
Constraints
1 <= n <= 10^4
1 <= d <= 100
1 <= epochs <= 10^4
0 < lr <= 1
Example
Input
1 1 1 0.1
1 1
Output
0.200000
0.200000