def run_numeric_feature_column(normalizer_fn=None): price = {'price': [[1., 1., 1., 1., 1., 1.], [2., 2., 2., 2., 2., 2.], [3., 3., 3., 3., 3., 3.], [4., 4., 4., 4., 4., 4.]]} print(price['price']) price_column = feature_column.numeric_column('price', shape=[6], normalizer_fn=normalizer_fn) price_transformed_tensor = feature_column.input_layer(price, [price_column]) with tf.Session() as session: print('Result:') print(session.run([price_transformed_tensor]))
def run_embedding_feature_column(): example = {'example': [['A'], ['B'], ['C'], ['D'], ['E'], ['F'], ['G'], ['H'], ['I'], ['J']]} print(example['example']) example_column = feature_column.categorical_column_with_hash_bucket('example', hash_bucket_size=15) example_column_embedding = feature_column.embedding_column(example_column, dimension=4) example_transformed_tensor = feature_column.input_layer(example, [example_column_embedding]) with tf.Session() as session: session.run(tf.global_variables_initializer()) print('Result:') print(session.run([example_transformed_tensor]))
def run_categorical_hash_bucket_feature_column(): example = {'example': [['A'], ['B'], ['C'], ['D']]} print(example['example']) example_column = feature_column.categorical_column_with_hash_bucket( 'example', hash_bucket_size=7) example_column_identy = feature_column.indicator_column(example_column) example_transformed_tensor = feature_column.input_layer( example, [example_column_identy]) with tf.Session() as session: print('Result:') print(session.run([example_transformed_tensor]))
def run_categorical_identity_feature_column(): example = {'example': [[1], [2], [8], [4]]} print(example['example']) example_column = feature_column.categorical_column_with_identity( 'example', num_buckets=10) example_column_identity = feature_column.indicator_column(example_column) example_transformed_tensor = feature_column.input_layer( example, [example_column_identity]) with tf.Session() as session: # session.run(tf.global_variables_initializer()) session.run(tf.tables_initializer()) print('Result:') print(session.run([example_transformed_tensor]))
def run_categorical_vocabulary_list_feature_column(): example = {'example': [['A'], ['B'], ['C'], ['D']]} print(example['example']) example_column = feature_column.categorical_column_with_vocabulary_list( 'example', vocabulary_list=['A', 'D']) example_column_identy = feature_column.indicator_column(example_column) example_transformed_tensor = feature_column.input_layer( example, [example_column_identy]) with tf.Session() as session: # session.run(tf.global_variables_initializer()) session.run(tf.tables_initializer()) print('Result:') print(session.run([example_transformed_tensor]))
def run_bucketized_feature_column(): price = { 'price': [[1., 1., 1., 1., 1., 1.], [2., 2., 2., 2., 2., 2.], [3., 3., 3., 3., 3., 3.], [4., 4., 4., 4., 4., 4.]] } print(price['price']) price_column = feature_column.numeric_column('price', shape=[6]) bucket_price = feature_column.bucketized_column(price_column, [0, 2, 3.5, 5]) price_transformed_tensor = feature_column.input_layer( price, [bucket_price]) with tf.Session() as session: print('Result:') print(session.run([price_transformed_tensor]))