Ejemplo de ajustes por mínimos cuadrados

px = {22, 19, 18, 23, 30, 20, 18, 19, 28, 25, 
          27};
py = {45,  40, 45, 43, 59, 43, 43, 44, 57, 48, 
          50};
p = Transpose[{px, py}];
MatrixForm[p]
ptos = 
        ListPlot[p, PlotStyle -> {PointSize[0.03]}, 
          PlotRange -> {{16, 31}, {34, 
                60}}];

Ajuste Lineal   f(x) = a+bx  (por mínimos cuadrados):

A = Transpose[{px/px, px}];
A // MatrixForm

ul = Inverse[Transpose[A] . A] . Transpose[A] . py // N

f[x_] := ul . {1, x}
f[x]

linea = 
        Plot[f[x], {x, 16, 31}, 
          PlotStyle -> {Thickness[ .01], 
              RGBColor[1, 0, 0]}];
Show[linea, ptos]

Ajuste Cuadrático  f(x) = a + b x  + c (x^2) (por mínimos cuadrados):

A = Transpose[{px/px, px, px^2}];
A // MatrixForm

u2 = Inverse[Transpose[A] . A] . Transpose[A] . py // N

g[x_] := u2 . {1, x, x^2}
g[x]

curva = 
        Plot[g[x], {x, 16, 31}, 
          PlotStyle -> {Thickness[ .01], 
              RGBColor[0, 0, 1]}];
Show[curva, ptos]

Show[linea, curva, ptos]