【发布时间】:2018-02-14 21:56:18
【问题描述】:
通过一个模型,不幸的是,我生成了少量数据点(总共 7 个)。对他们来说,我必须拟合一个分布,从中绘制 PDF 和 CDF,并从 CDF 计算某些概率点(例如,60%、75%、95%)的 x_values。
我已经开发了一种方法来做到这一点,但我觉得它非常不雅,如果能帮助我找到更强大的解决方案,我将不胜感激。这是我所拥有的:
import numpy as np
import seaborn as sns
x = [0.09, 1.08, -0.42, 0.08, -0.28, -0.65, -0.04]
probability = 0.6
pdf = sns.distplot(x, norm_hist=False, kde=True)
plt.show()
cdf = sns.distplot(x,
hist_kws=dict(cumulative=True),
kde_kws=dict(cumulative=True)).get_lines()[0].get_data()
plt.show()
ix = np.where(cdf[1] > probability)
ix = np.array([ix])
print('At %1.f probability the risk premium is approx %0.2f PLN'
% (int(probability*100), float(cdf[0].item(ix.item(0)))))
如果有人能指出我以更好的方式解决我的问题,我将不胜感激。谢谢!
【问题讨论】:
标签: python numpy matplotlib scipy seaborn