How to derive the least squares solution for linear regression? We have $n$ dots: $(x_1,y_1)\cdots (x_n,y_n)$.
We know that if we use the Least squares method we will get a line $y=mx+b$ that giving the minimal value for the function $w=\sum_{i=1}^n (mx_i+b-y_i)^2$.
I need to prove that $w$ maintains:
$$b=\frac{\sum_{i=1}^n x_i^2\sum_{i=1}^ny_i -\sum_{i=1}^nx_i\sum_{i=1}^nx_iy_i}{n(\sum_{i=1}^nx_i^2)-(\sum_{i=1}^nx_i)^2 } \\ and: \\m=\frac{n(\sum_{i=1}^nx_iy_i-\sum_{i=1}^nx_i \sum_{i=1}^ny_i}{n\sum_{i=1}^nx_i^2-(\sum_{i=1}^nx_i)^2}$$
I'm really don't know how to begin, and I'd like to get any help.
Thank you!

This post is an adjunct to the solution of @SA-255525, who solved the problem via the calculus. Another option is to use linear algebra.
Start with a crisp definition. We have a sequence of measurements of the form $\left\{ x_{k}, y_{k} \right\}_{k=1}^{m}$ and the trial function is $y(x) = c_{0} + c_{1}x$.
This implies the linear system
$$
\begin{align}
\mathbf{A} c &= y \\
\left[
\begin{array}{ccc}
  1 & x_{1} \\
  1 & x_{2} \\
  \vdots & \vdots \\
  1 & x_{m}
\end{array}
\right]
\left[
\begin{array}{c}
  c_{0} \\
  c_{1}
\end{array}
\right]
&=
\left[
\begin{array}{}
  y_{1}  \\
  y_{2}   \\
  \vdots \\
  y_{m}  
\end{array}
\right].
\end{align}
$$
By definition the least squares solution $c$ minimizes the sum of the squares of the residuals given by
$$
  \left[
\begin{array}{c}
  c_{0} \\
  c_{1}
\end{array}
\right]
_{LS} 
=
\left\{
  \left[
\begin{array}{c}
  c_{0} \\
  c_{1}
\end{array}
\right]
\in
\mathbb{R}^{2}
\colon
\lVert
  \mathbf{A} c - y
\rVert_{2}^{2}
\text{ is minimized}
\right\}
$$
One solution path uses column vectors. The column structure of the system matrix is 
$$
\mathbf{A} =
\left[
\begin{array}{cc}
  \mathbf{1} & x
\end{array}
\right].
$$
Using the normal equations $\mathbf{A}^{\mathrm{T}}\mathbf{A}c = \mathbf{A}^{\mathrm{T}} y$, the least squares solution is
$$
  c_{LS} = \left( \mathbf{A}^{\mathrm{T}}\mathbf{A} \right)^{-1} \mathbf{A}^{\mathrm{T}} y.
$$
This is the same solution found earlier. Note that
$$
\mathbf{A}^{\mathrm{T}} y = 
\left[
  \begin{array}{c}
    \mathbf{1}\cdot y\\
    x \cdot y
  \end{array}
\right],
\qquad
 \mathbf{A}^{\mathrm{T}}\mathbf{A} =
\left[
  \begin{array}{cc}
    \mathbf{1}\cdot\mathbf{1}  & \mathbf{1}\cdot x \\
    x \cdot \mathbf{1} & x \cdot x
  \end{array}
\right],
\qquad
\left( \mathbf{A}^{\mathrm{T}}\mathbf{A} \right)^{-1} = 
\left( \det \mathbf{A}^{\mathrm{T}}\mathbf{A} \right)^{-1}
\left[
  \begin{array}{rr}
      x \cdot x & -\mathbf{1}\cdot x \\
    -x \cdot \mathbf{1} & \mathbf{1}\cdot\mathbf{1}
  \end{array}
\right].
$$
To connect the two notations use
$$
\det \mathbf{A}^{\mathrm{T}}\mathbf{A} = 
\left( 
\mathbf{1}\cdot\mathbf{1}
\right) \left( 
x \cdot x
\right)
-
\left( 
\mathbf{1}\cdot x
\right)^{2},
$$
and
$$
\mathbf{1}\cdot\mathbf{1} = \sum_{k=1}^{m}(1) = m,
\quad
\mathbf{1}\cdot x = x\cdot\mathbf{1} = \sum_{k=1}^{m}x_{k},
\quad
\mathbf{1}\cdot y = \sum_{k=1}^{m} y_{k},
\quad
x \cdot y = \sum_{k=1}^{m} x_{k} y_{k}.
$$
