 <p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html" rel="nofollow">numpy.polyfit</a></p> <blockquote> <p>Fit a polynomial p(x) = p[0] * x**deg + ... + p[deg] of degree deg to points (x, y). Returns a vector of coefficients p that minimises the squared error.</p> </blockquote> <p>Example from the docs: </p> <pre><code>&gt;&gt;&gt; x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) &gt;&gt;&gt; y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) &gt;&gt;&gt; z = np.polyfit(x, y, 3) &gt;&gt;&gt; z array([ 0.08703704, -0.81349206, 1.69312169, -0.03968254]) </code></pre>