In statistics and machine learning, the log likelihood helps to measure how well a model explains the data. This complex probability simplifies calculations and is widely used to adapt the model during training, especially in techniques such as maximum likelihood estimation (MLE) and logistic regression.
The likelihood function represents the probability of the observed data given specific model parameters. Taking the logarithm of the likelihood simplifies calculations, especially when dealing with very small probability values.
Equation:
Log Likelihood (LL) = log ( 𝑃 ( Data
| Parameters ) )
Since the logarithm is a monotonic function, maximizing likelihood and maximizing log likelihood are equivalent.
Why Use Log Likelihood?
- Numerical stability: When the opportunities are very small, the undercurrent prevents.
- Simplification: Converts products into money, making the calculation easier.
- Adaptation efficiency: Helps change rapidly to shield -based methods.
- Better interpretation: Mutical analysis and model simplifies evaluation.
Application in Machine Learning
Many algorithms use log likelihood during training, such as Logistic Regression, Naive Bayes, and Hidden Markov Models (HMMs). It helps in estimating parameters that best explain the given data.
Example:
In logistic regression, the log likelihood function is:
LL(θ)=i=1∑n[yilog(pi)+(1−yi)log(1−pi)]
where 𝑦𝑖 is the true label and 𝑝𝑖 is the predicted probability.
Python Implementation
import numpy as np
probabilities = [0.9, 0.8, 0.3, 0.4]
labels = [1, 1, 0, 0]
log_likelihood = 0
for p, y in zip(probabilities, labels):
log_likelihood += y * np.log(p) + (1 - y) * np.log(1 - p)
print(f"Log Likelihood: {log_likelihood}")
Output:
Log Likelihood: -1.1160242This example calculates the total log likelihood based on predicted probabilities and true labels.
Related Articles: