Data Assumption: yi∈R Model Assumption: yi=w⊤xi+ϵi where ϵi∼N(0,σ2) ⇒yi|xi∼N(w⊤xi,σ2)⇒P(yi|xi,w)=1√2πσ2e−(x⊤iw−yi)22σ2
In words, we assume that the data is drawn from a "line" w⊤x through the origin (one can always add a bias / offset through an additional dimension, similar to the Perceptron). For each data point with features xi, the label y is drawn from a Gaussian with mean w⊤xi and variance σ2. Our task is to estimate the slope w from the data.
Estimating with MLE
w=argmaxwP(y1,x1,...,yn,xn|w)=argmaxwn∏i=1P(yi,xi|w)Because data points are independently sampled.=argmaxwn∏i=1P(yi|xi,w)P(xi|w)Chain rule of probability.=argmaxwn∏i=1P(yi|xi,w)P(xi)xi is independent of w, we only model P(yi|x)=argmaxwn∏i=1P(yi|xi,w)P(xi) is a constant - can be dropped=argmaxwn∑i=1log[P(yi|xi,w)]log is a monotonic function=argmaxwn∑i=1[log(1√2πσ2)+log(e−(x⊤iw−yi)22σ2)]Plugging in probability distribution=argmaxw−12σ2n∑i=1(x⊤iw−yi)2First term is a constant, and log(ez)=z=argminw1nn∑i=1(x⊤iw−yi)2Always minimize; 1n makes the loss interpretable (average squared error).
We are minimizing a loss function, l(w)=1n∑ni=1(x⊤iw−yi)2. This particular loss function is also known as the squared loss or Ordinary Least Squares (OLS). OLS can be optimized with gradient descent, Newton's method, or in closed form.
Closed Form:w=(XX⊤)−1Xy⊤ where X=[x1,…,xn] and y=[y1,…,yn].
Estimating with MAP
Additional Model Assumption: P(w)=1√2πτ2e−w⊤w2τ2 w=argmaxwP(w|y1,x1,...,yn,xn)=argmaxwP(y1,x1,...,yn,xn|w)P(w)P(y1,x1,...,yn,xn)=argmaxwP(y1,x1,...,yn,xn|w)P(w)=argmaxw[n∏i=1P(yi,xi|w)]P(w)=argmaxw[n∏i=1P(yi|xi,w)P(xi|w)]P(w)=argmaxw[n∏i=1P(yi|xi,w)P(xi)]P(w)=argmaxw[n∏i=1P(yi|xi,w)]P(w)=argmaxwn∑i=1logP(yi|xi,w)+logP(w)=argminw12σ2n∑i=1(x⊤iw−yi)2+12τ2w⊤w=argminw1nn∑i=1(x⊤iw−yi)2+λ||w||22
This objective is known as Ridge Regression. It has a closed form solution of: w=(XX⊤+λI)−1Xy⊤, where X=[x1,…,xn] and y=[y1,…,yn].