math - Least square method in python -


i have 2 lists of data, 1 x values , other corresponding y values. how can find best fit? i've tried messing scipy.optimize.leastsq can't seem right.

any appreciated

i think simpler use numpy.polyfit, performs least squares polynomial fit. simple snippet:

import numpy np  x = np.array([0,1,2,3,4,5]) y = np.array([2.1, 2.9, 4.15, 4.98, 5.5, 6])  z = np.polyfit(x, y, 1) p = np.poly1d(z)  #plotting import matplotlib.pyplot plt xp = np.linspace(-1, 6, 100) plt.plot(x, y, '.', xp, p(xp)) plt.show() 

enter image description here


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -