Given a dataset of discrete outcomes, compute the Empirical Probability Mass Function (PMF). For each unique value in the data, calculate the fraction of times it appears. Return a dictionary mapping each unique value to its probability.
def empirical_pmf(data: list) -> dict:
counts = {}
n = len(data)
for x in data:
counts[x] = counts.get(x, 0) + 1
pmf = {}
for k in sorted(counts.keys()):
pmf[k] = round(counts[k] / n, 4)
return pmfn to get the probability.