[SciPy-User] Fitting a Gaussian

josef.pktd at gmail.com josef.pktd at gmail.com
Mon Jan 17 17:09:16 EST 2011


On Mon, Jan 17, 2011 at 4:55 PM, Benedikt Riedel <briedel at wisc.edu> wrote:
> Hi all,
>
> I am a bit dumbfounded. I have been trying to figure out how to fit a
> gaussian to a data set that I have. The only thing I have been able to dig
> up with so far is that I have to get scipy to compute the mean and standard
> deviation for me and then basically plug those into a gaussian. Just seems a
> little bit odd to me considering that Octave has the mygaussfit function
> included or is there an easier method?

I don't know what a mygaussfit does, but we have this:

>>> rvs = np.random.randn(200)
>>> from scipy import stats
>>> stats.norm.fit(rvs)
(-0.0092383641087203858, 1.0567583206929831)
>>> loc, scale = stats.norm.fit(rvs)
>>> rvs.mean()
-0.0092383641087203858
>>> rvs.std()
1.0567583206929831
>>> loc, scale
(-0.0092383641087203858, 1.0567583206929831)
>>> myfrozennorm = stats.norm(loc=loc, scale=scale)
>>> myfrozennorm.cdf(2)
0.97137010763982468
>>>

This assumes that all observations are identically distributed and
independent from each other. Otherwise, it get's a little bit more
complicated.

Josef

>
> Cheers,
>
> Ben
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>



More information about the SciPy-User mailing list