Problem 45851. Least Absolute Deviations (L1-norm) line fit - degree 1
Matlab's polyfit function is very handy to find least-squares regression. It minimizes the (L2-norm) of the estimation errors, by solving a linear system. <https://www.mathworks.com/help/matlab/ref/polyfit.html>
An often overlooked way to deal with these situations is to use Least Absolute Deviations (LAD) line fitting. It minimizes the L1-norm of the residuals, thus it is less sensitive to outliers that fall far away from the underlying model https://en.wikipedia.org/wiki/Least_absolute_deviations
- - -
You are given two vectors X and Y (coordinates of observations on a plane). Return a row vector P = [a, b] with the coefficients of the best-fit line, in the L1-norm sense. I.e., find a and b that minimize sum( abs( Y - a*X - b ) ) .
(compare your results with polyfit on the test suite!)
Solution Stats
Problem Comments
-
1 Comment
Alfonso Nieto-Castanon
on 23 Aug 2020
please fix testsuite (e.g. change "polyval(P_lad,X)" to "polyval(P,X)")
Solution Comments
Show commentsProblem Recent Solvers5
Suggested Problems
-
Make the vector [1 2 3 4 5 6 7 8 9 10]
47194 Solvers
-
Count letters occurence in text, specific to words with a given length.
149 Solvers
-
57 Solvers
-
4993 Solvers
-
Divide elements by sum of elements
124 Solvers
More from this Author10
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!