# Draw the Best-Fit Line
# Core implementation example — ackleywill.com

import numpy as np

x = np.array([1., 2., 3., 4., 5.])
y = np.array([2., 3., 5., 4., 6.])
design = np.column_stack([x, np.ones_like(x)])
slope, intercept = np.linalg.lstsq(design, y, rcond=None)[0]

prediction = slope * x + intercept
residual = y - prediction
mae = np.mean(np.abs(residual))
rmse = np.sqrt(np.mean(residual ** 2))
print("Slope / intercept:", slope, intercept)
print("MAE / RMSE:", mae, rmse)
