[英]getting mean and standard deviation from best-fit normal distribution using seaborn library
I have a set of data and I used seaborn
library to plot the histogram, apply kernel density estimate and fit a normal distribution to the data.我有一组数据,我使用seaborn
库来绘制直方图,应用核密度估计并拟合数据的正态分布。 However I would like to extract the mean and standard deviation of the best-fit normal distribution.但是我想提取最佳拟合正态分布的均值和标准差。 How could I get these values as outputs from the function distplot
of this library?我怎样才能从这个库的函数distplot
得到这些值作为输出? My code:我的代码:
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])
A bug in seaborn
library is that, it doesn't generate the label for the fitted normal distribution but it does for histogram or kernel density. seaborn
库中的一个错误是,它不会为拟合正态分布生成标签,但会为直方图或核密度生成标签。
How can I get the normal distribution parameters and make a label for it in the plot?如何获取正态分布参数并在图中为其制作标签?
Don't get them as outputs from the plot;不要将它们作为情节的输出; use the estimator object you are passing to it:使用您传递给它的 estimator 对象:
norm.fit(C)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.