scikit prep logo scikit prep: onehot

1 2 3 4 5 6 7 8
Notes

The base use of the OneHotEncoder is demonstrated below.

import numpy as np
from sklearn.preprocessing import OneHotEncoder

arr = np.array(["low", "low", "high", "medium"]).reshape(-1, 1)
enc = OneHotEncoder(sparse=False, handle_unknown='ignore')
enc.fit_transform(arr)

Because we have set handle_unknown="ignore" we can run this line of code without causing an error.

enc.transform([["zero"]])