Skip to content

Instantly share code, notes, and snippets.

@crawles
Created March 5, 2019 02:08
Show Gist options
  • Save crawles/8fa7ff4774994d796fdd6bb1d0d41a80 to your computer and use it in GitHub Desktop.
Save crawles/8fa7ff4774994d796fdd6bb1d0d41a80 to your computer and use it in GitHub Desktop.
fc = tf.feature_column
CATEGORICAL_COLUMNS = ['sex', 'n_siblings_spouses', 'parch', 'class', 'deck',
'embark_town', 'alone']
NUMERIC_COLUMNS = ['age', 'fare']
def one_hot_cat_column(feature_name, vocab):
return tf.feature_column.indicator_column(
tf.feature_column.categorical_column_with_vocabulary_list(feature_name,
vocab))
feature_columns = []
for feature_name in CATEGORICAL_COLUMNS:
# Need to one-hot encode categorical features.
vocabulary = dftrain[feature_name].unique()
feature_columns.append(one_hot_cat_column(feature_name, vocabulary))
for feature_name in NUMERIC_COLUMNS:
feature_columns.append(tf.feature_column.numeric_column(feature_name,
dtype=tf.float32))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment