skspatial.objects.Line.best_fit¶
- classmethod Line.best_fit(points: Union[ndarray, Sequence], tol: Optional[float] = None, **kwargs) Line [source]¶
Return the line of best fit for a set of points.
- Parameters
- pointsarray_like
Input points.
- tolfloat | None, optional
Keyword passed to
Points.are_collinear()
(default None).- kwargsdict, optional
Additional keywords passed to
numpy.linalg.svd()
- Returns
- Line
The line of best fit.
- Raises
- ValueError
If the points are concurrent.
Examples
>>> from skspatial.objects import Line
>>> points = [[0, 0], [1, 2], [2, 1], [2, 3], [3, 2]] >>> line = Line.best_fit(points)
The point on the line is the centroid of the points.
>>> line.point Point([1.6, 1.6])
The line direction is a unit vector.
>>> line.direction.round(3) Vector([0.707, 0.707])