def testDeepColumnsSucceedForDNN(self):
real_valued = feature_column.real_valued_column("income", 3)
bucket = feature_column.bucketized_column(
feature_column.real_valued_column("price", 2),
boundaries=[0., 10., 100.])
hashed_sparse = feature_column.sparse_column_with_hash_bucket("wire", 10)
features = {
"income":
constant_op.constant([[20., 10, -5], [110, 0, -7], [-3, 30, 50]]),
"price":
constant_op.constant([[20., 200], [110, 2], [-20, -30]]),
"wire":
sparse_tensor.SparseTensor(
values=["omar", "stringer", "marlo"],
indices=[[0, 0], [1, 0], [2, 0]],
dense_shape=[3, 1])
}
embeded_sparse = feature_column.embedding_column(
hashed_sparse, 10, initializer=init_ops.constant_initializer(133.7))
output = feature_column_ops.input_from_feature_columns(
features, [real_valued, bucket, embeded_sparse])
with self.test_session():
variables_lib.global_variables_initializer().run()
# size of output = 3 (real_valued) + 2 * 4 (bucket) + 10 (embedding) = 21
self.assertAllEqual(output.eval().shape, [3, 21])
feature_column_ops_test.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录