Fit linear models that are not dragged around by outliers.
1. lad_fit(X, y): least absolute deviations, minw∑n∣yn−w⊤xn∣ (the MLE under a Laplace likelihood). Solve it as a linear program with scipy.optimize.linprog(..., method="highs") over v=(w1,…,wD,e1,…,eN): minimize ∑nen subject to w⊤xn−yn≤en and −(w⊤xn−yn)≤en, with w unbounded. Return w (length D).
2. huber_fit(X, y, delta, n_iter): minimize the Huber loss ∑nℓδ(yn−w⊤xn), where ℓδ(r)=r2/2 for ∣r∣≤δ and δ∣r∣−δ2/2 otherwise, by iteratively reweighted least squares:
- start from the ordinary least-squares solution;
- repeat
n_iter times: compute residuals rn, set weights sn=min(1,δ/∣rn∣) (with sn=1 when rn=0), and solve the weighted least-squares problem minw∑nsn(yn−w⊤xn)2.
Return w. X contains a bias column where needed.