Dose finding slope/intercept using the formula of m,b gives best fit line always In linear regression?
The formulae you mentioned gives the coefficients of the line of best fit.The values are derived using the least squares method, where the goal is to minimize the sum of squared errors. Following is the derivation for the values of m and b.
Let the line of best fit be $$\hat{y} = m*x + b$$ We then  try to find the coefficients m and b which minimize the sum of squared errors between the actual value y and the observed value $\hat{y}$. \begin{align}
SSE &amp;= \sum_{i=1}^{n}(y_{i}-\hat{y_{i}})^2 \\
&amp;=\sum_{i=1}^{n}(y_{i}-m*x_{i}-b)^2
\end{align}
Taking the first derivative of SSE with respect to c and equating to zero.
\begin{align}
\frac{\partial SSE}{\partial b} &amp;= \sum_{i=1}^{n}-2*(y_{i}-m*x_{i}-b)\\
0 &amp;= \sum_{i=1}^{n}-2*(y_{i}-m*x_{i}-b)
\end{align}
Therefore we get c as $$ b = \bar{y} - m*\bar{x}$$ Similarly in order to find m we take the partial derivative of SSE with respect to m and equate it to zero.
\begin{align}
\frac{\partial SSE}{\partial m} &amp;= \sum_{i=1}^{n}-2x_{i}*(y_{i}-m*x_{i}-b)\\
0 &amp;= \sum_{i=1}^{n}-2x_{i}*(y_{i}-m*x_{i}-b)\\
0 &amp;= \sum_{i=1}^{n}x_{i}*(y_{i}-m*x_{i}-b)\\
0 &amp;= \sum_{i=1}^{n}x_{i}*y_{i} - \sum_{i=1}^{n}m*x_{i}^2 - \sum_{i=1}^{n}b*x_{i}
\end{align}
Substituting b and solving for m we get $$m = \frac{n\sum xy - \sum x\sum y}{n\sum x^2 - (\sum x)^2}$$