Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python & Scipy: How to fit a von mises distribution?

I'm trying to fit a von Mises distribution, from scipy (http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.vonmises.html)

So I tried

from scipy.stats import vonmises
kappa = 3
r = vonmises.rvs(kappa, size=1000)
plt.hist(r, normed=True,alpha=0.2)

It returns

enter image description here

However, when I fit the data on it

vonmises.fit(r)
# returns (1.2222011312461918, 0.024913780423670054, 2.4243546157480105e-30)

vonmises.fit(r, loc=0, scale=1)
# returns (1.549290021706847, 0.0013319431181202394, 7.1653626652619939e-29)

But none of the value returned is the parameter of Von Mises, kappa.

What is the returning value? Ifeel the second is loc, or mean value. But have no idea what the first returned value is.

And how should I fit a von mises distribution?

like image 352
cqcn1991 Avatar asked Aug 18 '16 14:08

cqcn1991


People also ask

What is Python used for?

Python is commonly used for developing websites and software, task automation, data analysis, and data visualization. Since it's relatively easy to learn, Python has been adopted by many non-programmers such as accountants and scientists, for a variety of everyday tasks, like organizing finances.

What is A += in Python?

The Python += operator lets you add two values together and assign the resultant value to a variable. This operator is often referred to as the addition assignment operator.

Which language is used in Python?

Python is written in C (actually the default implementation is called CPython).

Is Python hard to learn?

Python is widely considered among the easiest programming languages for beginners to learn. If you're interested in learning a programming language, Python is a good place to start. It's also one of the most widely used.


1 Answers

The returned values are kappa, loc and scale. Unfortunately, the von Mises pdf does not seem to yield itself to fitting. It does fit correctly if you fix the scale:

>>> vonmises.fit(r, fscale=1)
(2.994517240859579, -0.0080482378119089287, 1)
like image 120
Tim Fuchs Avatar answered Sep 20 '22 03:09

Tim Fuchs