polyfit

numeric.fitting.polyfit(x, y, degree, func=False)

Polynomail fitting.

Parameters
  • x – (array_like) x data array.

  • y – (array_like) y data array.

  • degree – (int) Degree of the fitting polynomial.

  • func – (boolean) Return fit function (for predict function) or not. Default is False.

Returns

Fitting parameters and function (optional).

Examples:

from mipylib.numeric import fitting

x = linspace(0, 4*pi, 10)
y = sin(x)

#Plot data points
plot(x, y, 'ro', fill=False, size=1)

#Use polyfit to fit a 7th-degree polynomial to the points
r = fitting.polyfit(x, y, 7)

#Plot fitting line
xx = linspace(0, 4*pi, 100)
p = r[0]
yy = fitting.polyval(p, xx)
plot(xx, yy, '-b')
title('Polynomial fitting example')
../../../../_images/mi_1.4.1_lab_polyfit.png