Login using Social Account
     Continue with GoogleLogin using your credentials
Scikit-learn provides a class OneHotEncoder
for performing One Hot Encoding. This class is present in the preprocessing
submodule of sklearn
.
We can perform One Hot Encoding in the same way in which we imputed the missing values, i.e, create an instance and fit and transform variables.
We'll use the fit_transform()
method here which performs both fitting and transforming at a single time. Its syntax is the same as the fit()
method. It returns a SciPy sparse matrix.
Also, we can use the instance variable categories_
to display the categories of the encoder.
Refer to OneHotEncoder documentation for further details about the method.
Import OneHotEncoder
from the preprocessing
submodule of sklearn
.
Create an instance with the name encoder
for the class OneHotEncoder
.
Use the fit_transform()
method on encoder
. Specify train_data[['ocean_proximity']]
as the dataset. Store the output in a variable named one_hot
.
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...