15

I am using scipy.stats.expon.fit(data) to fit an exponential distribution to my data. This appears to return two values where I would expect one. The documentation online doesn't seem to say what fit() returns but looking at the source, I am guessing it is both a location and scale parameter. Can you fix the location parameter to 0 when doing the fitting?

Simd
  • 19,447
  • 42
  • 136
  • 271
  • @mdml Thank you. I would like to run fit but have the location fixed to 0. It seems this isn't the default behaviour. (It is odd that it has a location parameter at all to be honest for the exponential distribution.) – Simd Aug 01 '14 at 17:06
  • 1
    Duplicate: http://stackoverflow.com/questions/21610034/fitting-distribution-with-fixed-parameters-in-scipy/ (Yeah, I know I already answered. Shame on me.) – Warren Weckesser Aug 01 '14 at 17:18
  • @WarrenWeckesser Ah well I will happily delete it but it would be great if the docs could be updated! – Simd Aug 01 '14 at 17:19

1 Answers1

16

In the call to expon.fit, use floc=0:

In [5]: data = expon.rvs(0, 1.5, 1000)

In [6]: loc, scale = expon.fit(data, floc=0)

In [7]: scale
Out[7]: 1.4878030368336586

In [8]: loc
Out[8]: 0
Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214
  • Thank you! Is that in the documentation anywhere? Or in other words, how did you know this? – Simd Aug 01 '14 at 17:18
  • 1
    You have to read the docstring of `expon.fit` pretty closely to find it, but it is mentioned in there. Read the description of `kwds` in the "Parameters" section. – Warren Weckesser Aug 01 '14 at 17:21
  • 2
    Oh wow. The official web page has loads less information in it than the docstring!! – Simd Aug 01 '14 at 17:25