deoxysdefense forme gen rapidash gen swanna gen thusyou can see that it is really easy to build your own transformation mapping scheme with the help of python dictionaries and use the mapfunction from pandas to transform the ordinal feature encoding categorical features we have mentioned several times in the past that machine learning algorithms usually work well with numerical values you might now be wondering we already transformed and mapped the categorical variables into numeric representations in the previous sections so why would we need more levels of encoding againthe answer to this is pretty simple if we directly fed these transformed numeric representations of categorical features into any algorithmthe model will essentially try to interpret these as raw numeric features and hence the notion of magnitude will be wrongly introduced in the system simple example would be from our previous output dataframea model fit on generationlabel would think that value and so on while order is important in the case of pokemon generations (ordinal variable)there is no notion of magnitude here generation is not larger than generation and generation is not smaller than generation hence models built using these features directly would be sub-optimal and incorrect models there are several schemes and strategies where dummy features are created for each unique value or label out of all the distinct categories in any feature in the subsequent sectionswe will discuss some of these schemes including one hot encodingdummy codingeffect codingand feature hashing schemes one hot encoding scheme considering we have numeric representation of any categorical feature with labelsthe one hot encoding schemeencodes or transforms the feature into binary featureswhich can only contain value of or each observation in the categorical feature is thus converted into vector of size with only one of the values as (indicating it as activelet' take our pokemon dataset and perform some one hot encoding transformations on some of its categorical features in [ ]poke_df[['name''generation''legendary']iloc[ : out[ ]name generation legendary octillery gen false helioptile gen false dialga gen true deoxysdefense forme gen true rapidash gen false swanna gen false considering the dataframe depicted in the outputwe have two categorical featuresgeneration and legendarydepicting the pokemon generations and their legendary status firstwe need to transform these text labels into numeric representations the following code helps us achieve this in [ ]from sklearn preprocessing import onehotencoderlabelencoder transform and map pokemon generations gen_le labelencoder(