【问题标题】:getting mean and standard deviation from best-fit normal distribution using seaborn library使用 seaborn 库从最佳拟合正态分布中获取均值和标准差
【发布时间】:2016-06-29 23:52:45
【问题描述】:

我有一组数据,我使用seaborn 库绘制直方图,应用核密度估计并对数据拟合正态分布。但是我想提取最佳拟合正态分布的均值标准差。我怎样才能从这个库的函数distplot 中获取这些值作为输出? 我的代码:

import seaborn as sns
from scipy.stats import norm 
sns.set_style("darkgrid")
sns.set_context("paper", font_scale=1, rc={"lines.linewidth": 1.5, "axes.linewidth": 1.0, "axes.labelsize": 15, "xtick.labelsize": 10, "ytick.labelsize": 10, "font.family":'serif','font.serif':'Ubuntu'})

fig, axes = plt.subplots(1, 1, figsize=(10, 10))
sns.distplot(C,
            fit=norm, kde=True,
            fit_kws ={"color": "#fc4f30", "lw": 1.5},
            kde_kws={"color": "y", "lw": 1.5},
            hist_kws={"histtype": "stepfilled", "linewidth": 1, "alpha": 0.1, "color": "b"},
            norm_hist=True, ax=axes[0,0])

seaborn 库中的一个错误是,它不会为拟合的正态分布生成标签,但会为直方图或核密度生成标签。

如何获取正态分布参数并在图中为其制作标签?

【问题讨论】:

    标签: python scipy seaborn


    【解决方案1】:

    不要将它们作为情节的输出;使用您传递给它的估算器对象:

    norm.fit(C)
    

    【讨论】: