November 2017
Intermediate to advanced
1035 pages
11h 31m
English
In this recipe, we'll look at working with categorical variables in a different way. In the event that only one or two categories of the feature are important, it might be wise to avoid the extra dimensionality, which might be created if there are several categories.
There's another way to work with categorical variables. Instead of dealing with the categorical variables using OneHotEncoder, we can use LabelBinarizer. This is a combination of thresholding and working with categorical variables.
To show how this works, load the iris dataset:
>>> from sklearn import datasets as d >>> iris = d.load_iris() >>> target = iris.target
Import the LabelBinarizer() method and create an object:
>>> from ...Read now
Unlock full access