Weibull distribution calculation Runtimewarning overflow

Clash Royale CLAN TAG#URR8PPPWeibull distribution calculation Runtimewarning overflow
I was trying to use the code below to calculate the Weibull distribution, but I am getting a runtime warning of overflow exp: given that my data is a list of 6 members , but containing big numbers, it seems that the calculation takes a lot and my plot is not like what I see in the link.
I used the fit and got the error :
too many values to unpack (expected 2)
Weibull example code 1
import scipy.stats as s
import numpy as np
import matplotlib.pyplot as plt
def weib(x,n,a):
return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)
data = [ 79000 , 85900 , 95000, 101000, 155250 , 280000]
(loc, scale) = s.exponweib.fit_loc_scale(data, 1, 1)
print loc, scale
x = np.linspace(data[0], data[-1], 1000)
plt.plot(x, weib(x, loc, scale))
plt.hist(data, data[-1], normed=True)
plt.show()
Method 2 :
I tried this code : using this source ( code 2 )
data = [ 79000 , 85900 , 95000, 101000, 155250 , 280000]
xdata = np.asarray(data)
a = 1. # shape
s1 = np.random.weibull(a, 1000)
x = xdata
def weib(x,n,a):
return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)
count, bins, ignored = plt.hist(np.random.weibull(5.,1000))
x = xdata
scale = count.max()/weib(x, 1., 5.).max()
plt.plot(x, weib(x, 1., 5.)*scale)
plt.show()
I got some results like these :

I don't know why I don't get the line curve together with the bands, and I am not sure whether s1 also should be a random parameter or should be chosen repectively
Update 1 :
Searching for another method, I used the following code, but the problem here is that I get the x and y values as NAN
# Expoential Weibull PDF
def expweibPDF(x, k, lam, alpha):
return (alpha * (k/lam) *
((x/lam)**(k-1)) *
((1 - exp(-(x/lam)**k))**(alpha-1)) *
exp(-(x/lam)**k))
# Expoential Weibull CDF
def exp_cdf(x, k, lam, alpha):
return (1 - exp(-(x / lam)**k))**alpha
# Expoential Weibull Inverse CDF
def exp_inv_cdf(p, k, lam, alpha):
return lam * ( - log( (1 - p)**(1/alpha) ))**(1/k)
# parameters for the fit - alpha = 1.0 reduces to normal Webull
# the shape parameters k = 5.0 and lam = 1.0 are demonstrated on Wikipedia:
# https://en.wikipedia.org/wiki/Weibull_distribution
alpha = 1.0
k0 = 5.0
lam0 = 1.0
x =
y =
# create a Weibull distribution
random.seed(123)
n = len(data)
for i in range(1,n) :
p=data[i]
x0 = exp_inv_cdf(p,k0,lam0,alpha)
x += [ x0 ]
y += [ expweibPDF(x0,k0,lam0,alpha) ]
# now fit the Weibull using python library
# setting f0=1 should set alpha = 1.0
# so, shape parameters should be the k0 = 5.0 and lam = 1.0
(exp1, k1, loc1, lam1) = stats.exponweib.fit(y,floc=0, f0=1)
print (exp1, k1, loc1, lam1)
fig, ax = plt.subplots(2, 1)
ax[0].plot(x,y, 'ro', lw=2)
ax[1].plot(x,stats.exponweib.pdf(x,exp1,k1,loc1,lam1), 'ro', lw=2)
plt.show()
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.