logo

... scikit prep: onehot



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"]])

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.