scipy.stats.genpareto#

scipy.stats.genpareto = <scipy.stats._continuous_distns.genpareto_gen object>[原始碼]#

廣義帕雷托連續隨機變數。

作為 rv_continuous 類別的實例,genpareto 物件繼承了它的一系列通用方法(完整列表請見下方),並以針對此特定分佈的詳細資訊加以完善。

註解

genpareto 的機率密度函數為

\[f(x, c) = (1 + c x)^{-1 - 1/c}\]

定義域為:當 \(c \ge 0\) 時,\(x \ge 0\);當 \(c < 0\) 時,\(0 \le x \le -1/c\)

genparetoc 作為形狀參數,適用於 \(c\)

\(c=0\) 時,genpareto 簡化為指數分佈 expon

\[f(x, 0) = \exp(-x)\]

\(c=-1\) 時,genpareto[0, 1] 上是均勻分佈

\[f(x, -1) = 1\]

上述機率密度定義為「標準化」形式。若要平移及/或縮放分佈,請使用 locscale 參數。具體而言,genpareto.pdf(x, c, loc, scale)genpareto.pdf(y, c) / scale 完全等效,其中 y = (x - loc) / scale。請注意,平移分佈的位置不會使其成為「非中心」分佈;某些分佈的非中心推廣在不同的類別中提供。

範例

>>> import numpy as np
>>> from scipy.stats import genpareto
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1, 1)

計算前四個動差

>>> c = 0.1
>>> mean, var, skew, kurt = genpareto.stats(c, moments='mvsk')

顯示機率密度函數 (pdf)

>>> x = np.linspace(genpareto.ppf(0.01, c),
...                 genpareto.ppf(0.99, c), 100)
>>> ax.plot(x, genpareto.pdf(x, c),
...        'r-', lw=5, alpha=0.6, label='genpareto pdf')

或者,可以呼叫分佈物件(作為函數)以固定形狀、位置和尺度參數。這會返回一個「凍結」的 RV 物件,其中包含給定的固定參數。

凍結分佈並顯示凍結的 pdf

>>> rv = genpareto(c)
>>> ax.plot(x, rv.pdf(x), 'k-', lw=2, label='frozen pdf')

檢查 cdfppf 的準確性

>>> vals = genpareto.ppf([0.001, 0.5, 0.999], c)
>>> np.allclose([0.001, 0.5, 0.999], genpareto.cdf(vals, c))
True

產生隨機數字

>>> r = genpareto.rvs(c, size=1000)

並比較直方圖

>>> ax.hist(r, density=True, bins='auto', histtype='stepfilled', alpha=0.2)
>>> ax.set_xlim([x[0], x[-1]])
>>> ax.legend(loc='best', frameon=False)
>>> plt.show()
../../_images/scipy-stats-genpareto-1.png

方法

rvs(c, loc=0, scale=1, size=1, random_state=None)

隨機變量。

pdf(x, c, loc=0, scale=1)

機率密度函數。

logpdf(x, c, loc=0, scale=1)

機率密度函數的對數。

cdf(x, c, loc=0, scale=1)

累積分布函數。

logcdf(x, c, loc=0, scale=1)

累積分布函數的對數。

sf(x, c, loc=0, scale=1)

生存函數(也定義為 1 - cdf,但 sf 有時更準確)。

logsf(x, c, loc=0, scale=1)

生存函數的對數。

ppf(q, c, loc=0, scale=1)

百分點函數(cdf 的反函數 — 百分位數)。

isf(q, c, loc=0, scale=1)

反生存函數(sf 的反函數)。

moment(order, c, loc=0, scale=1)

指定階數的非中心動差。

stats(c, loc=0, scale=1, moments=’mv’)

平均數('m')、變異數('v')、偏度('s')和/或峰度('k')。

entropy(c, loc=0, scale=1)

RV 的(微分)熵。

fit(data)

通用資料的參數估計。 有關關鍵字引數的詳細文件,請參閱 scipy.stats.rv_continuous.fit

expect(func, args=(c,), loc=0, scale=1, lb=None, ub=None, conditional=False, **kwds)

關於分佈的函數(單一引數)的期望值。

median(c, loc=0, scale=1)

分佈的中位數。

mean(c, loc=0, scale=1)

分佈的平均數。

var(c, loc=0, scale=1)

分佈的變異數。

std(c, loc=0, scale=1)

分佈的標準差。

interval(confidence, c, loc=0, scale=1)

圍繞中位數的等面積信賴區間。