On Tue, Apr 14, 2009 at 6:51 AM, ning luwen <ninglu...@gmail.com> wrote: > i already have tried. > > and try to use the module scipy.optimize.leastsq to fit, but neither > get a good return or just break out like this. > > is there any other good way?or something wrong with my code? >
I suggest you try the scipy list. Google for Smart Questions before you do that, though. Also, when asking for help on a list, you need to mention what you've already tried. You've only wasted a day for a useless answer. Also, please keep responses on the list. Other people on the list are much smarter than I am. > > > Traceback (most recent call last): > File "fitgamma.py", line 33, in <lambda> > e = lambda v, x, y: (fp(v,x)-y) > File "fitgamma.py", line 26, in <lambda> > fp = lambda v, x: x**(v[0]-1)/(v[1]**v[0]*gamma(v[0]))*exp(-x/v[1]) > File "mtrand.pyx", line 1236, in mtrand.RandomState.gamma > ValueError: shape <= 0 > Traceback (most recent call last): > File "fitgamma.py", line 46, in <module> > v, success = leastsq(e, v0, args=(xdata,ydata),maxfev=100000) > File "/usr/lib/python2.6/dist-packages/scipy/optimize/minpack.py", > line 270, in leastsq > retval = > _minpack._lmdif(func,x0,args,full_output,ftol,xtol,gtol,maxfev,epsfcn,factor,diag) > minpack.error: Error occured while calling the Python function named <lambda> > > > > ps:the part code in fitting the distribution(xdata,ydata are vectors > of the data need to fit. > > fp = lambda v, x: x**(v[0]-1)/(v[1]**v[0]*gamma(v[0]))*exp(-x/v[1]) > e = lambda v, x, y: (fp(v,x)-y) > v0 = [6, 3] > v, success = leastsq(e, v0, args=(xdata,ydata),maxfev=100000) > > > > > > On Mon, Apr 13, 2009 at 8:49 PM, Kushal Kumaran > <kushal.kuma...@gmail.com> wrote: >> On Mon, Apr 13, 2009 at 1:40 PM, ning luwen <ninglu...@gmail.com> wrote: >>> hi, >>> i need to fit a gamma distribution, is there any module can do the job? >>> >> >> Did you try google? Searching for python curve fitting returns some >> promising results. >> >> -- >> kushal >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > -- http://mail.python.org/mailman/listinfo/python-list