Skip to content

Instantly share code, notes, and snippets.

@spin-glass
Created May 2, 2017 05:09
Show Gist options
  • Save spin-glass/dad8ba9fa8d641875c27c65813aaf8a3 to your computer and use it in GitHub Desktop.
Save spin-glass/dad8ba9fa8d641875c27c65813aaf8a3 to your computer and use it in GitHub Desktop.
2クラス分類時のone-hot label
from sklearn.preprocessing import LabelBinarizer, OneHotEncoder
label = ['a', 'b', 'a']
binarized_label = LabelBinarizer().fit_transform(label) # [[1], [2], [2]]
# 以下は2クラスの場合のみ必要
one-hot_label = OneHotEncoder().fit_transform(binarized_label).toarray()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment