Skip to content

Instantly share code, notes, and snippets.

@crawles
Last active March 5, 2019 02:09
Show Gist options
  • Save crawles/7f4cf1a6f9fca2012e60b82912554f50 to your computer and use it in GitHub Desktop.
Save crawles/7f4cf1a6f9fca2012e60b82912554f50 to your computer and use it in GitHub Desktop.
example = dict(dftrain.head(1))
class_fc = tf.feature_column.indicator_column(tf.feature_column.categorical_column_with_vocabulary_list('class', ('First', 'Second', 'Third')))
print('Feature value: "{}"'.format(example['class'].iloc[0]))
print('One-hot encoded: ', tf.keras.layers.DenseFeatures([class_fc])(example).numpy())
# Feature value: "Third"
# One-hot encoded: [[0. 0. 1.]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment