累積分布関数(CDF: Cumulative Distribution Function)とは
確率変数Xがある値x以下(X <= x)の値となる確率です。
例えばサイコロを投げたときに「出る目が4以下となる確率」や「出る目が4から6の目が出る確率」といった、ある範囲の確率を求めるときに使用します。
確率質量関数(PMF: Probability Mass Function)との区別:
- PMFはある値xを得る確率
- CDFはある値x以下の値を得る確率
CDFプロット
import numpy as np
import seaborn as sns
pmf = df['col'].value_counts(normalize=True).sort_index()
cdf = np.cumsum(pmf)
fig, ax = plt.subplots()
ax.plot(pmf.index, pmf.values, label='PMF')
ax.plot(cdf.index, cdf.values, label='CDF')
ax.legend()
plt.show()