Your question is Implement Simple Linear Regression. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
At Lyft, a small analytics tool needs a basic linear regression function without using external ML libraries. Given paired numeric observations, compute the best-fit line y = mx + b using ordinary least squares.
Write a function that takes two arrays, x_values and y_values, and returns the slope and intercept of the regression line.
x_values: list of numbers of length ny_values: list of numbers of length n[slope, intercept]x_values are identical, return [].Use the formulas:
slope = sum((xi - mean_x) * (yi - mean_y)) / sum((xi - mean_x)^2)intercept = mean_y - slope * mean_xdef linear_regression(x_values, y_values):