Implement:
def train_linear_regression(
input: np.ndarray,
target: np.ndarray,
lr: float,
epochs: int,
) -> tuple[np.ndarray, np.ndarray]:
"""
input: shape (batch_size, in_features)
target: shape (batch_size,), one target value per sample
lr: learning rate
epochs: number of full-batch gradient-descent steps
Returns:
weight: shape (1, in_features)
bias: shape (1,)
"""
Your function should:
weight to zeros, shape (1, in_features), and bias to zeros, shape (1,). One output feature, matching target.target once, up front, to (batch_size, 1), the shape 01-hypothesis-function's linear actually produces, never leave it (batch_size,) and let it silently broadcast against a prediction later.epochs times: compute gradients with 03-mse-gradient's mse_gradient, then apply one step with 04-gd-step's gd_step.weight, bias.Use the functions you already implemented in the earlier questions rather than reimplementing their logic inside the training loop.
Click "Run Tests" to test your implementation