Tag: OneHot Encoding

  • OneHot encoding of columns in a pandas dataframe using get_dummies.

    The simplest way I found for performing OneHot encoding is using pandas.get_dummies method. In just one line of code you can OneHot encode selected columns in a pandas dataframe. Also, it returns the dataframe with other columns intact. The renaming of new columns of the encoded data is taken care off too. Let’s start by…

  • Convert class labels to categories using keras

    Class labels can be converted to OneHot encoded array using keras.utils.to_categorical.The resultant array has number of rows equal to the number of samples, and number of columns equal to the number of classes. Let’s take an example of an arrray containing labels.First we need to import numpy to create the labels array and then define the labels array. The labels contain four…