TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Ordinal Encoding

Feature Engineering
Easy

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.

Loading visualization...

Examples

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]

Hint 1

Create a dictionary from each ordered category to its index.

Hint 2

Look up each input value in that dictionary.

Requirements

  • Map each value to its zero-based position in ordering.
  • Preserve the input value order.
  • Return a list of integers.

Constraints

  • ordering contains unique values.
  • Every input value appears in ordering.
  • Time limit: 300 ms.
Try Similar Problems
Frequency EncodingTarget EncodingCyclic EncodingOne Hot EncodingInteraction Features

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Ordinal Encoding

Feature Engineering
Easy

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.

Loading visualization...

Examples

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]

Hint 1

Create a dictionary from each ordered category to its index.

Hint 2

Look up each input value in that dictionary.

Requirements

  • Map each value to its zero-based position in ordering.
  • Preserve the input value order.
  • Return a list of integers.

Constraints

  • ordering contains unique values.
  • Every input value appears in ordering.
  • Time limit: 300 ms.
Try Similar Problems
Frequency EncodingTarget EncodingCyclic EncodingOne Hot EncodingInteraction Features

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.