Python – Calculates the log-likelihood of a distribution in Python

Calculates the log-likelihood of a distribution in Python… here is a solution to the problem.

Calculates the log-likelihood of a distribution in Python

What is the simple way to calculate the log-likelihood of any distribution suitable for the data?

Solution

OP’s solution.

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

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

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

Since it is a standard distribution included in the SciPy library, pdf and logpdf can be found and used very easily in the following ways

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

Note that this corresponds to the log-likelihood function defined here

Related Problems and Solutions