पॉलीफिट काम करता है, लेकिन वहां कम से कम स्क्वायर मिनीमाइज़र हैं। मैं कम से
http://www.astro.rug.nl/software/kapteyn-beta/kmpfittutorial.html
यह और अधिक मजबूत है कि polyfit kmpfit, उपलब्ध की सिफारिश करेंगे, और वहाँ अपने पृष्ठ पर एक उदाहरण दिखाता है जो कि कैसे एक सरल रैखिक फिट है कि एक 2 आदेश कर की मूल बातें प्रदान करना चाहिए करने के लिए है बहुपद फिट।
def model(p, v, x, w):
a,b,c,d,e,f,g,h,i,j,k = p #coefficients to the polynomials
return a*v**2 + b*x**2 + c*w**2 + d*v*x + e*v*w + f*x*w + g*v + h*x + i*y + k
def residuals(p, data): # Function needed by fit routine
v, x, w, z = data # The values for v, x, w and the measured hypersurface z
a,b,c,d,e,f,g,h,i,j,k = p #coefficients to the polynomials
return (z-model(p,v,x,w)) # Returns an array of residuals.
#This should (z-model(p,v,x,w))/err if
# there are error bars on the measured z values
#initial guess at parameters. Avoid using 0.0 as initial guess
par0 = [1.0, 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0]
#create a fitting object. data should be in the form
#that the functions above are looking for, i.e. a Nx4
#list of lists/tuples like (v,x,w,z)
fitobj = kmpfit.Fitter(residuals=residuals, data=data)
# call the fitter
fitobj.fit(params0=par0)
इन बातों की सफलता फिट करने के लिए प्रारंभिक मूल्यों पर बारीकी से निर्भर है, इसलिए सावधानी से यदि संभव हो तो चुना है। इतने सारे मुफ्त पैरामीटर के साथ समाधान प्राप्त करना एक चुनौती हो सकती है।
मैंने इस समस्या को हल करने के लिए यहां कोड पोस्ट किया है [https://github.com/mrocklin/multipolyfit ](https://github.com/mrocklin/multipolyfit) – MRocklin