Skip to content

Instantly share code, notes, and snippets.

@spin-glass
Created May 2, 2017 00:57
Show Gist options
  • Save spin-glass/c08dc73a7bf4815c258485ead8db6a11 to your computer and use it in GitHub Desktop.
Save spin-glass/c08dc73a7bf4815c258485ead8db6a11 to your computer and use it in GitHub Desktop.
one-hot label
from keras.utils import np_utils
from sklearn.preprocessing import LabelEncoder
import numpy as np
feature_labels = np.array([1, 1, 2, 3, 4, 3, 4])
encoder = LabelEncoder()
encoder.fit(feature_labels)
feature_labels = encoder.transform(feature_labels)
feature_labels = np_utils.to_categorical(feature_labels)
'''
array([[ 1., 0., 0., 0.],
[ 1., 0., 0., 0.],
[ 0., 1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment