Loading content...
In statistical analysis and machine learning, understanding the frequency distribution of observed data is a foundational skill. When working with discrete variables—variables that take on distinct, countable values—we often need to compute the relative frequency of each unique value, which provides an empirical estimate of the underlying probability distribution.
Given a collection of integer observations drawn from a discrete source, your task is to compute the discrete frequency distribution. For each unique value in the dataset, calculate its relative frequency—the proportion of times that value appears relative to the total number of observations.
Mathematical Formulation:
For a dataset containing N total observations, if a particular value x appears count(x) times, its relative frequency is:
$$\text{relative_frequency}(x) = \frac{\text{count}(x)}{N}$$
The sum of all relative frequencies will always equal 1.0, representing the complete distribution of the data.
Output Requirements:
Why This Matters: Understanding frequency distributions is essential in machine learning for tasks such as:
samples = [1, 2, 2, 3, 3, 3][[1, 0.16666666666666666], [2, 0.3333333333333333], [3, 0.5]]The dataset contains 6 total observations:
• Value 1 appears 1 time → relative frequency = 1/6 ≈ 0.1667 • Value 2 appears 2 times → relative frequency = 2/6 ≈ 0.3333 • Value 3 appears 3 times → relative frequency = 3/6 = 0.5
The results are returned sorted by value in ascending order: [[1, 0.1667], [2, 0.3333], [3, 0.5]].
samples = [1, 2, 3, 4][[1, 0.25], [2, 0.25], [3, 0.25], [4, 0.25]]This is a uniform distribution where each of the 4 unique values appears exactly once out of 4 total observations:
• Each value has relative frequency = 1/4 = 0.25
The results show an equal probability of 0.25 for each value, characteristic of a discrete uniform distribution.
samples = [5, 5, 5, 5, 5][[5, 1.0]]All 5 observations are the same value (5). This represents a degenerate distribution or point mass:
• Value 5 appears 5 times out of 5 → relative frequency = 5/5 = 1.0
The entire probability mass is concentrated on a single value.
Constraints