import numpy as np from sklearn import preprocessing step defining sample labels after importing the packageswe need to define some sample labels so that we can create and train the label encoder we will now define the following sample labelssample input labels input_labels ['red','black','red','green','black','yellow','white'step creating training of label encoder object in this stepwe need to create the label encoder and train it the following python code will help in doing thiscreating the label encoder encoder preprocessing labelencoder(encoder fit(input_labelsfollowing would be the output after running the above python codelabelencoder(step checking the performance by encoding random ordered list this step can be used to check the performance by encoding the random ordered list following python code can be written to do the sameencoding set of labels test_labels ['green','red','black'encoded_values encoder transform(test_labelsprint("\nlabels ="test_labelsthe labels would get printed as followslabels ['green''red''black'nowwe can get the list of encoded values word labels converted to numbers as followsprint("encoded values ="list(encoded_values)the encoded values would get printed as followsencoded values [