LinearLeastSquares
Finds the best curve to fit a set of points through minimizing the sum of the squares of the offset of each point from the curve.
The constructor takes an Array<[number, number]>, which is an Array of tuples. Each tuple is a point represented by [x, y].
const LinearLeastSquares = ; let points = 2 4 3 5 5 7 7 10 9 15; let fit = points;
After you have initialized an instance of LinearLeastSquares
with the points
it should analyze, you just need to have it compute_fit()
.
result = fit;
The result object contains 4 keys:
m: 15182926829268293 b: 030487804878048674 rmse: 07986268703523449 r_squared: 09595301473319301
m
: is the slope of the fit line.
b
: is the y-intercept of the slop line.
rmse
: is the root mean square error, it tells you how concentrated the data
is around the line of best fit.
r_squared
: is the R-squared statistical measure, evaluates the scatter of the
data points around the fitted regression line.
If you want to generate a set of points with the specified result
object, you
can do the following:
predicted_points = fit; 0 030487804878048674 1 1823170731707316 2 33414634146341453 3 4859756097560974 4 6378048780487804 5 7896341463414633 6 9414634146341463 7 10932926829268293 8 1245121951219512
If you would like to generate any point on the specified result
object, you
can do the following:
predicted_point = fit; 12 18524390243902438
Source docs are available at https://github.com/jjviscomi/LinearLeastSquares/blob/master/docs/classes/linear_least_squares.linearleastsquares.md