Given an array with [x, y] points, e.g.:
p0 = np.random.rand(21, 2)
p1 = np.array([[0, 0], [0, 1], [0, 2], [0, 3]])
I would like to get a straight line [segment] approximation of these points. Least squares method is acceptable, other error functions may be fine too. Note that the set of points in general is not a function, i.e. as shown above in p1
, there are multiple y
values associated with x = 0
.
There is no slope, intercept solution for a vertical set of points, e.g. p1
, therefore np.polyfit
, scipy.stats.linregress
are not solutions I'm looking for. Think geometry, not statistics.