Ordinal encoding maps ordered categories to integer positions. The ordering list defines the rank explicitly, with its first category mapped to 0, its second category mapped to 1, and so on.
Every input value appears in ordering. Return one integer for each value, preserving the original sequence.
Input: values = ["low", "medium", "high", "medium"], ordering = ["low", "medium", "high"]
Output: [0, 1, 2, 1]
Explanation: The categories occupy positions 0, 1, and 2 in the supplied ordering.
Input: values = ["S", "M", "L", "XL", "S"], ordering = ["S", "M", "L", "XL"]
Output: [0, 1, 2, 3, 0]
Create a dictionary from each ordered category to its index.
Look up each input value in that dictionary.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Ordinal encoding maps ordered categories to integer positions. The ordering list defines the rank explicitly, with its first category mapped to 0, its second category mapped to 1, and so on.
Every input value appears in ordering. Return one integer for each value, preserving the original sequence.
Input: values = ["low", "medium", "high", "medium"], ordering = ["low", "medium", "high"]
Output: [0, 1, 2, 1]
Explanation: The categories occupy positions 0, 1, and 2 in the supplied ordering.
Input: values = ["S", "M", "L", "XL", "S"], ordering = ["S", "M", "L", "XL"]
Output: [0, 1, 2, 3, 0]
Create a dictionary from each ordered category to its index.
Look up each input value in that dictionary.
Sign in to take notes on this problem
Accepts: array
Accepts: array