If I have a function $y=f(x)\approx ax+b$ where $a,b$ are constants that correlate to a set of $n$ points, could I use the following as an approximation of the gradient?
$$a\approx\frac1n\sum_{i=1}^n\frac{y_i}{x_i}$$ I'm not sure if my question is clear so please ask me if I need to clarify
No. If you try to apply linear regression for $n$ distinct points, then you should choose $a,b$ such that$$\sum_{i=1}^{n}(y_i-ax_i-b)^2$$be a minimum. After a simple minimization, $a$ is obtained as follows:$$a={n\sum_{i=1}^n x_iy_i-\sum_{i=1}^n x_i\sum_{i=1}^n y_i\over n\sum_{i=1}^n x_i^2-\left(\sum_{i=1}^n x_i\right)^2}$$therefore$$f'(x)\approx {n\sum_{i=1}^n x_iy_i-\sum_{i=1}^n x_i\sum_{i=1}^n y_i\over n\sum_{i=1}^n x_i^2-\left(\sum_{i=1}^n x_i\right)^2}$$