Created
March 5, 2019 02:08
-
-
Save crawles/8fa7ff4774994d796fdd6bb1d0d41a80 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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