Simple curve fitting with CurveFit (or alternative)

Just for fun:
To fit a polynom you can use

"""
Fit y = f(x) to nth order polynomial.
Returns list of polynomial coefficients.
"""
function polyfit(x,y,n)
	@assert length(x) > n
	A = [k^n for k in x, n in 0:n]
	A\y
end

To reason about the fit you would need to look for measures often found under goodness of fit, but I am not sure which are implemented by julia packages. If you want to look into one of those methods I think the package HypothesisTests is a good resource.

Also if you try to fit a log transformed exponential function you should use a weighted least square fit to compensate for the transform.

1 Like