Created
May 2, 2017 00:57
-
-
Save spin-glass/c08dc73a7bf4815c258485ead8db6a11 to your computer and use it in GitHub Desktop.
one-hot label
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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