【发布时间】:2019-11-08 21:51:45
【问题描述】:
我知道您可以使用 seaborn.distplot 将数据绘制为直方图并在其上叠加分布。我知道一个允许您传入 pdf 函数的参数。在源代码中,它看起来像是在内部调用 fit() 来进行训练。我想知道是否有办法对模型进行预训练,然后直接使用它。
我曾尝试使用代表我的分布的 lambda 函数,但我不断收到错误。 我也尝试将参数传递给 seaborn.distplot 以帮助训练我想要的设置,但这也不起作用。
方法 1 - 对预训练模型使用 lambda:
import seaborn as sns
from scipy import stats
params = stats.exponweib.fit(data, floc=0, f0=1)
custom_weib = lambda x: stats.exponweib.pdf(x, *params)
sns.distplot(data, bins=bin_count, fit=custom_weib, norm_hist=True, kde=False, hist_kws={'log':True})
我看到此错误消息: AttributeError:'function'对象没有属性'fit' ^ 不能采用预训练模型。
方法 2 - 尝试将参数作为 fit 方法的一部分传递。(我不知道我这样做是否正确。)
import seaborn as sns
from scipy import stats
sns.distplot(data, bins=bin_count, norm_hist=True, kde=False, hist_kws=hist_kws, fit=stats.exponweib, floc=0, f0=1)
我得到了这个异常:TypeError: distplot() got an unexpected keyword argument 'floc' ^ 很明显我没有正确传递变量,但我不知道如何。
如果需要,这里是 Seaborn 源代码的链接:https://github.com/mwaskom/seaborn/blob/master/seaborn/distributions.py
【问题讨论】:
-
“火车”这个词对于统计拟合来说可能有点脱离上下文?如果没有这个概念,你能描述问题吗?是不是你想修复一个参数而只适合另一个?
-
@ImportanceOfBeingErnest - 是的,这是正确的。我希望能够修复训练参数。
floc和f0