Skip to content

Instantly share code, notes, and snippets.

@apetrov
Created July 16, 2019 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apetrov/3140216791e01da27d664b63206f7963 to your computer and use it in GitHub Desktop.
Save apetrov/3140216791e01da27d664b63206f7963 to your computer and use it in GitHub Desktop.
feature_columns = []
for feature_name in CATEGORICAL_COLUMNS:
vocabulary = df[feature_name].unique()
column = tf.feature_column.categorical_column_with_vocabulary_list(feature_name, vocabulary)
embedding_column = tf.feature_column.embedding_column(column, dimension=len(vocabulary))
feature_columns.append(embedding_column)
for feature_name in NUMERIC_COLUMNS:
feature_columns.append(tf.feature_column.numeric_column(feature_name, dtype=tf.float32))
model = tf.keras.models.Sequential([
tf.keras.layers.DenseFeatures(feature_columns),
tf.keras.layers.Dense(64),
tf.keras.layers.Dense(2,activation='sigmoid')
])
X_train, X_test, y_train, y_test = train_test_split(df, df.y)
ds = tf.data.Dataset.from_tensor_slices((dict(X_train), y_train))
model.fit(ds,epochs=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment