【问题标题】:What does max(count)*fit/max(fit) suppose to mean? What is the term 'fit' supposed to convey?max(count)*fit/max(fit) 是什么意思? “适合”这个词应该表达什么?
【发布时间】:2020-03-09 14:06:34
【问题描述】:

docs.scipy.org 中有一个生成帕累托分布的代码。我可以理解大部分代码 sn-p 除了对 PDF(概率密度函数)使用术语“拟合”和公式:max(count)*fit/max(fit)

这里是sn-p的代码:

import matplotlib.pyplot as plt
a, m = 3., 2.  # shape and mode
s = (np.random.pareto(a, 1000) + 1) * m
count, bins, _ = plt.hist(s, 100, normed=True)
fit = a*m**a / bins**(a+1)
plt.plot(bins, max(count)*fit/max(fit), linewidth=2, color='r')
plt.show()

我在网上彻底搜索了公式:max(count)*fit/max(fit) 甚至用 pdf 替换了“适合”一词。但无法获得任何线索。请解释一下公式所传达的概念。

我假设使用术语“拟合”而不是 PDF,因为他们使用 PDF 的公式进行帕累托分布进行拟合。

最后,代码中的下划线'_'表达了什么:

count, bins, _ = plt.hist(s, 100, normed=True)

【问题讨论】:

  • _ 表明该值并不重要。 plt.hist 会返回三个值,最后一个不重要

标签: python matplotlib distribution pareto-chart


【解决方案1】:

np.random.pareto 从 Pareto-II 分布中抽取随机样本。因此,得到的数据是这种分布的实现,而不是分布的概率密度。

在对plt.hist 的调用中,我们使用normed=True 参数。这会标准化数据并在 y 轴上绘制我们样本的密度,而不是频率。

然后,我们希望将帕累托分布拟合到我们随机采样的数据中,并将此分布绘制在我们的数据之上。

为此,我们首先计算由bins 定义的x 值处的帕累托分布的概率密度,参数为am。这是我们对适合度的定义:fit = a*m**a / bins**(a+1)

max(count) * fit / max(fit) 术语的必要性有点难以捉摸。我认为很清楚为什么我们会在绘图命令中包含fit,但为什么要使用比率max(count) / max(fit)?实际上,我不是 100% 确定。

max(count) / max(fit) 看起来可能是通过将帕累托分布拟合到我们的数据而进行的偏差校正。

【讨论】:

  • 谢谢@Ralph,你解释得很好。但是,您没有提到 max(count)*fit/max(fit)。
  • @Bipin 抱歉,我错过了max(count) * fit / max(fit) 位。我不太明白为什么它是必要的。我去问问同事。
  • 我必须衷心感谢您的努力和时间。
  • @Bipin 我鼓励将此问题发布到cross validated。我似乎无法解决这个问题
  • 我在交叉验证中发布。感谢您建议我发帖。
猜你喜欢
  • 2017-02-23
  • 1970-01-01
  • 2012-05-16
  • 2022-11-29
  • 2015-08-22
  • 1970-01-01
  • 2016-11-17
  • 2018-10-29
  • 2011-03-04
相关资源
最近更新 更多