Ordinal Categorical Encoding or Label Encoding
Amit Kumar
AI Engineer | Gen AI | Agentic AI | LLM | RAG | Machine Learning | Computer Vision | NLP | Deep Learning |
Ordinal data is a categorical, statistical data type where the variables have natural, ordered categories and the distances between the categories is not known.
For example:
- Student's grade in an exam (A, B, C or Fail).
- Educational level, with the categories: Elementary school, High school, College graduate, PhD ranked from 1 to 4.
- When the categorical variables are ordinal, the most straightforward best approach is to replace the labels by some ordinal number based on the ranks.
Let us do a practical !
import pandas as pd
import datetime