Purdue University student-support analytics needs a small baseline model that estimates an outcome from one numeric measurement. Implement univariate linear regression using the ordinary least-squares solution, without using machine-learning libraries.
Given paired feature values x and target values y, compute the line y = slope * x + intercept that minimizes the sum of squared prediction errors.
Implement fit_linear_regression(x, y), where x and y are nonempty lists of numbers with equal length. Return a two-element list [slope, intercept] containing floating-point values. The input guarantees that x contains at least two distinct values, so the slope is defined.
Use these formulas, where x_mean and y_mean are the respective averages:
slope = sum((x[i] - x_mean) * (y[i] - y_mean)) / sum((x[i] - x_mean)^2)intercept = y_mean - slope * x_meandef fit_linear_regression(x, y):