LinearRegression finds the best line in one call. Gradient descent walks there one step at a time. With more than one feature, both should land in the same place, given enough steps.
Write two_routes(rows, answers, rate, steps). Each row has the same number of features.
Route 1: gradient descent. Keep one weight per feature in an array w (all zeros at the start) and one intercept b = 0. Each step:
error = X @ w + b - y, for every row at once.grad_w = 2 * X.T @ error / n and grad_b = 2 * error.mean(), where n is the number of rows.w = w - rate * grad_w and b = b - rate * grad_b.Repeat exactly steps times.
Route 2: the library. Fit a LinearRegression model on the same rows.
Return a dict:
"descent": the weights from route 1 followed by its intercept, as one list."library": coef_ followed by intercept_, as one list.Round every number to 2 decimal places and use plain Python floats.