In [ ]:
from chempy.units import default_units as u
from chempy.util.regression import least_squares, plot_fit, irls, plot_least_squares_fit, least_squares_units
%matplotlib inline

In [ ]:
help(least_squares)

In [ ]:
x = [0, 1, 2, 3, 4+1e-9]
y = [3, 3.8, 5.2, 5.2, 10.8]

Simple OLS with plotting:


In [ ]:
res = least_squares(x, y)
plot_least_squares_fit(x, y, res)

Iterative least squares:


In [ ]:
res_irls = irls(x, y, irls.gaussian, itermax=20)
plot_least_squares_fit(x, y, res_irls)

In [ ]:
x

In [ ]:
y*u.m

In [ ]:
res_units = least_squares_units(x*u.s, y*u.m)
#plot_least_squares(x*u.s, y*u.m, res_units, x_unit=u.s, y_unit=u.m)

In [ ]:
res_units

In [ ]:
err = [.1, .2, .2, .8, 3]*u.m
res_weighted = least_squares_units(x*u.s, y*u.m, err**-2)
plot_least_squares_fit(x*u.s, y*u.m, res_weighted, err, x_unit=u.s, y_unit=u.m)

In [ ]: