Categorical encoding transforms categorical values into numerical representations so numeric analysis and outlier detectors can process them. section 4.9 section 9.0
Common encoding choices include:
- Ordinal encoding maps each category to a number, such as Red → 0, Blue → 1, and Green → 2. section 4.9
- Count encoding replaces each category with its frequency, so Red, Blue, and Green become 3, 2, and 1. section 4.9
- One-hot encoding replaces a categorical column with one binary column per unique value. section 4.9
Encoding baseball positions
Applying one-hot encoding to a baseball position column creates features such as Position_Catcher, Position_First_Base, and Position_Outfield. Each row receives one 1 for its position and 0 in the other position columns, while existing numeric features remain unchanged. section 4.9
df = pd.get_dummies(df)
Use pandas to replace categorical columns with binary indicator columns while retaining numeric features. section 4.9












