Frequency encoding replaces each category with the proportion of input positions containing that category. If a category appears c times in a list of n values, its encoding is
f=ncHere, c is the category count and n is len(values). Return one floating-point frequency for every input position in the same order.
Input: values = ["a", "b", "a", "c", "a"]
Output: [0.6, 0.2, 0.6, 0.2, 0.6]
Explanation: Category a occurs three times out of five, while b and c each occur once.
Input: values = ["cat", "dog", "cat", "cat", "dog"]
Output: [0.6, 0.4, 0.6, 0.6, 0.4]
Build a count dictionary in one pass over values.
Map each original value to its count divided by the total length.
Sign in to take notes on this problem
Accepts: array
Frequency encoding replaces each category with the proportion of input positions containing that category. If a category appears c times in a list of n values, its encoding is
f=ncHere, c is the category count and n is len(values). Return one floating-point frequency for every input position in the same order.
Input: values = ["a", "b", "a", "c", "a"]
Output: [0.6, 0.2, 0.6, 0.2, 0.6]
Explanation: Category a occurs three times out of five, while b and c each occur once.
Input: values = ["cat", "dog", "cat", "cat", "dog"]
Output: [0.6, 0.4, 0.6, 0.6, 0.4]
Build a count dictionary in one pass over values.
Map each original value to its count divided by the total length.
Sign in to take notes on this problem
Accepts: array