目前我有适合对数正态分布的代码。在
shape, loc, scale = sm.lognorm.fit(dataToLearn, floc = 0)
for b in bounds:
toPlot.append((b, currCount+sm.lognorm.ppf(b, s = shape, loc = loc, scale = scale)))
我希望能够将权重向量传递给拟合。目前我有一个解决方法,我将所有的权重四舍五入到2个小数点,然后重复每个值w
次,这样就可以正确地加权了。在
这个运行时间对我的计算机来说太慢了,所以我希望有一个更正确的解决方案。在
请告知是使用scipy还是numpy,使我的解决方案更快更有效
您可以使用numpy.repeat来提高解决方案的效率:
对
^{pr2}$numpy.repeat
性能的非常基本的性能测试:因此,对于您当前的方法,我得到了大约3.38,而对于
numpy.repeat
,我得到了0.75SciPy分布不实现加权拟合。然而,对于对数正态分布,有(未加权)maximum likelihood estimation的显式公式,这些公式很容易推广到加权数据。显式公式都是(实际上)平均值,对加权数据情况的概括是在公式中使用加权平均值。在
下面是一个脚本,它使用一个具有整数权重的小数据集演示计算,因此我们知道拟合参数的确切值应该是多少。在
输出是
^{pr2}$相关问题 更多 >
编程相关推荐