howto get fit parameters from seaborn distplot fit=?

匿名 (未验证) 提交于 2019-12-03 02:26:02

问题:

I'm using seaborn distplot (data, fit=stats.gamma)

How do I get the fit parameters returned?

Here is an example:

import numpy as np import pandas as pd import seaborn as sns from scipy import stats df = pd.read_csv ('RequestSize.csv') import matplotlib.pyplot as plt reqs = df['12 web pages'] reqs = reqs.dropna() reqs = reqs[np.logical_and (reqs > np.percentile (reqs, 0), reqs < np.percentile (reqs, 95))] dist = sns.distplot (reqs, fit=stats.gamma) 

回答1:

Use the object you passed to distplot:

stats.gamma.fit(reqs) 


回答2:

I confirm the above is true - the sns.distplot fit method is equivalent to the fit method in scipy.stats so you can get the parameters from there, e.g.:

from scipy import stats  ax = sns.distplot(e_t_hat, bins=20, kde=False, fit=stats.norm); plt.title('Distribution of Cointegrating Spread for Brent and Gasoil')  # Get the fitted parameters used by sns (mu, sigma) = stats.norm.fit(e_t_hat) print "mu={0}, sigma={1}".format(mu, sigma)  # Legend and labels  plt.legend(["normal dist. fit ($\mu=${0:.2g}, $\sigma=${1:.2f})".format(mu, sigma)]) plt.ylabel('Frequency')  # Cross-check this is indeed the case - should be overlaid over black curve x_dummy = np.linspace(stats.norm.ppf(0.01), stats.norm.ppf(0.99), 100) ax.plot(x_dummy, stats.norm.pdf(x_dummy, mu, sigma)) plt.legend(["normal dist. fit ($\mu=${0:.2g}, $\sigma=${1:.2f})".format(mu, sigma),            "cross-check"]) 



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!