Calculating loglikelihood of distributions in Python

≯℡__Kan透↙ 提交于 2021-02-08 07:44:27

问题


What is an easy way to calculate the loglikelihood of any distribution fitted to data?


回答1:


Solution by OP.

Python has 82 standard distributions which can be found here and in scipy.stats.distributions

Suppose you find the parameters such that the probability density function(pdf) fits the data as follows:

dist = getattr(stats.stats, 'distribution name')
params = dist.fit(data)

Then since it is a standard distribution included in the SciPy library, the pdf and logpdf can be found and used very easily in the following way:

LLH = dist.logpdf(data,*params).sum()

Note that that this corresponds to the loglikelihood function defined here.



来源:https://stackoverflow.com/questions/50588602/calculating-loglikelihood-of-distributions-in-python

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