CJ23rio
CJ23rio

Reputation: 43

Fitting data to a Generalized extreme value distribution

I've been trying to use scipy.stats.genextreme to fit my data to the generalized extreme value distribution. I've tried all of the methods that I could find, but I don't know why it won't fit the data.

I've tried both these methods:

import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import genextreme as gev

dataN = [0.0, 0.0, 0.122194513716, 0.224438902743, 0.239401496259, 0.152119700748, 
         0.127182044888, 0.069825436409, 0.0299251870324, 0.0199501246883, 0.00997506234414, 
         0.00498753117207, 0.0]

t = np.linspace(1,13,13)
fit = gev.fit(dataN,loc=3)
pdf = gev.pdf(t, *fit)
plt.plot(t, pdf)
plt.plot(t, dataN, "o")
print(fit)

as well as

popt, pcov = curve_fit(gev.pdf,t, dataN)
plt.plot(t,gev.pdf(*popt),'r-')

This is the result I got for the first one

The second method resulted in this

" ValueError: Unable to determine number of fit parameters."

Thanks for any help that you can give me!

Upvotes: 4

Views: 8400

Answers (1)

James Phillips
James Phillips

Reputation: 4647

According to the scipy.stats documentation at:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.genextreme.html

the fit() method uses the raw data, and it looks like you are passing the binned histogram data in your call to:

fit = gev.fit(dataN,loc=3)

Try passing in the raw data to see if it works as you need.

Upvotes: 6

Related Questions