线性模型中的分类特征通常被转换成稀疏向量

 

 

 

简介  |  TensorFlow https://tensorflow.google.cn/programmers_guide/low_level_intro

 

[教程9]具有TensorFlow的大规模线性模型 - 笔记ing - 博客园 https://www.cnblogs.com/yinghuali/p/7747591.html

 

 

import tensorflow  as tf

features = {
    'sales': [[5], [10], [8], [9]],
    'department': ['sports', 'sports', 'gardening', 'gardening']}

department_column = tf.feature_column.categorical_column_with_vocabulary_list(
    'department', ['sports', 'gardening'])
department_column = tf.feature_column.indicator_column(department_column)

columns = [
    tf.feature_column.numeric_column('sales'),
    department_column
]

inputs = tf.feature_column.input_layer(features, columns)
var_init = tf.global_variables_initializer()
table_init = tf.tables_initializer()
sess = tf.Session()
sess.run((var_init, table_init))
res = sess.run(inputs)

 

 

 

 

构建计算图

 

import tensorflow  as tf

eye_color = tf.feature_column.categorical_column_with_vocabulary_list('eye_color',
                                                                      vocabulary_list=['blue', 'blown', 'green'])

  

 

posted @ 2018-05-12 17:14  papering  阅读(572)  评论(0编辑  收藏  举报