# python – I make the code but condition is failed how to repair my code please help me

### Likelihoods

Now let us start implementing the actual classifier. We begin with a multinomial likelihood function. Implement function `multinomial_likelihood(probs, freqs)` that takes two arguments: `probs` are dictionary of probabilities of each character (in some language) and `freqs` is dictionary of absolute frequencies of each character (in some text we want to classify). This function has to return probability to obtain these absolute frequencies from multinomial distribution with given probabilities $$P((X_1 = f_1) cap (X_2 = f_2) cap ldots cap (X_k = f_k))$$ provided that $$(X_1, ldots, X_k)$$ is a system of multinomially distributed values with probabilities $$(p_1, ldots, p_k)$$. (You need the `factorial` function that can be imported from `math`.)

``````import math

def multinomial_likelihood(probs, freqs):
f = p = 1
n = len(probs)

for k, _ in probs.items():
if k in probs and k in freqs:
f *= math.factorial(freqs(k))
p *= probs(k) ** freqs(k)
else:
n -= 1

result = math.factorial(n) / f * p

return result
``````

check condition:

``````assert abs(multinomial_likelihood(probs={'a': 0.2, 'b': 0.5, 'c': 0.3},
freqs={'a': 2, 'b': 1, 'c': 2}) - 0.054) < 0.000001
assert abs(multinomial_likelihood(probs={'a': 0.2, 'b': 0.1, 'c': 0.3, 'd': 0.4},
freqs={'a': 2, 'b': 1, 'c': 2}) - 0.0108) < 0.000001
``````
``````---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)