调用 exponweib 的 std 时 Scipy 统计信息中的 isinf(mu) 错误?
isinf(mu) error in Scipy stats when calling std for exponweib?
我在冻结的 exponweib 分配上调用 std 时遇到此错误?
代码如下:
d = st.exponweib
params = d.fit(y)
arg = params[:-2]
loc = params[-2]
scale = params[-1]
rv1 = d(arg,loc,scale)
print rv1.std()
拟合后的参数为:
arg: (3.445136651705262, 0.10885378466279112)
loc: 11770.05
scale: 3.87424773976
这是错误:
ValueError Traceback (most recent call last)
<ipython-input-637-4394814bbb8c> in <module>()
11 rv1 = d(arg,loc,scale)
12
---> 13 print rv1.std()
.../anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyc in std(self)
487
488 def std(self):
--> 489 return self.dist.std(*self.args, **self.kwds)
490
491 def moment(self, n):
.../anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyc in std(self, *args, **kwds)
1259 """
1260 kwds['moments'] = 'v'
-> 1261 res = sqrt(self.stats(*args, **kwds))
1262 return res
1263
.../anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyc in stats(self, *args, **kwds)
1032 mu = self._munp(1, *goodargs)
1033 mu2 = mu2p - mu * mu
-> 1034 if np.isinf(mu):
1035 # if mean is inf then var is also inf
1036 mu2 = np.inf
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
请告诉我我正在做的事情有什么问题或如何避免这种情况。
exponweib
分布有两个必需参数 a
、c
和两个可选参数 loc
和 scale
。当您调用 d(arg, loc, scale)
时,结果是 arg
被解释为 a
,loc
被解释为 c
,scale
被解释为 loc
。由于您的 arg
是两个元素的元组,因此您最终会得到一个随机变量元组,这两个都不是您想要的。
解决方案:解压元组:d(*arg, loc, scale)
。或者更简单,使用
rv1 = d(*params)
它会为您解压缩所有参数,而无需您提取和命名它们。
顺便说一句,当您想提供自己的随机变量的位置和比例时,最好将它们作为命名参数传递,例如 d(3, 5, loc=90, scale=0.3)
。这避免了你遇到的情况,当这些参数中的一些被解释为其他东西时,因为你没有得到正确的参数。在您的示例中,d(arg, loc=loc, scale=scale)
会立即引发错误,"missing 1 required positional argument: 'c'" 而不是使用 loc 而不是 c.
我在冻结的 exponweib 分配上调用 std 时遇到此错误?
代码如下:
d = st.exponweib
params = d.fit(y)
arg = params[:-2]
loc = params[-2]
scale = params[-1]
rv1 = d(arg,loc,scale)
print rv1.std()
拟合后的参数为:
arg: (3.445136651705262, 0.10885378466279112)
loc: 11770.05
scale: 3.87424773976
这是错误:
ValueError Traceback (most recent call last)
<ipython-input-637-4394814bbb8c> in <module>()
11 rv1 = d(arg,loc,scale)
12
---> 13 print rv1.std()
.../anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyc in std(self)
487
488 def std(self):
--> 489 return self.dist.std(*self.args, **self.kwds)
490
491 def moment(self, n):
.../anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyc in std(self, *args, **kwds)
1259 """
1260 kwds['moments'] = 'v'
-> 1261 res = sqrt(self.stats(*args, **kwds))
1262 return res
1263
.../anaconda/lib/python2.7/site-packages/scipy/stats/_distn_infrastructure.pyc in stats(self, *args, **kwds)
1032 mu = self._munp(1, *goodargs)
1033 mu2 = mu2p - mu * mu
-> 1034 if np.isinf(mu):
1035 # if mean is inf then var is also inf
1036 mu2 = np.inf
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
请告诉我我正在做的事情有什么问题或如何避免这种情况。
exponweib
分布有两个必需参数 a
、c
和两个可选参数 loc
和 scale
。当您调用 d(arg, loc, scale)
时,结果是 arg
被解释为 a
,loc
被解释为 c
,scale
被解释为 loc
。由于您的 arg
是两个元素的元组,因此您最终会得到一个随机变量元组,这两个都不是您想要的。
解决方案:解压元组:d(*arg, loc, scale)
。或者更简单,使用
rv1 = d(*params)
它会为您解压缩所有参数,而无需您提取和命名它们。
顺便说一句,当您想提供自己的随机变量的位置和比例时,最好将它们作为命名参数传递,例如 d(3, 5, loc=90, scale=0.3)
。这避免了你遇到的情况,当这些参数中的一些被解释为其他东西时,因为你没有得到正确的参数。在您的示例中,d(arg, loc=loc, scale=scale)
会立即引发错误,"missing 1 required positional argument: 'c'" 而不是使用 loc 而不是 c.