目录
一、Estimator简介
Estimator是TensorFlow对完整模型的高级表示。Tensorflow提供一个包含多个API层的编程堆栈:
Estimator封装了操作:训练、评估、预测、导出以供使用。
二、数据集
通过tf.data模块,构建输入管道,将数据传送到模型中。tf.data模块返回的是Dataset对象,每个Dataset包含(feature_dict, labels)对。
https://blog.youkuaiyun.com/woniu201411/article/details/89249689
三、定义特征列
特征列视为原始数据和Estimator之间的媒介。要创建特征列,需要调用tf.feature_column模块的函数。
1、数值列
tf.feature_column.numeric_column将具有默认数据类型(tf.float32)的数值指定为模型输入。
2、分桶列
tf.feature_column.bucketized_column将数字列根据数值范围分为不同的类别(为模型中加入非线性特征,提高模型的表达能力)。
3、分类标识列
tf.feature_column.categorical_column_with_identity将每个分桶表示一个唯一整数,模型可以在分类标识列中学习每个类别各自的权重。
4、分类词汇列
tf.feature_column.categorical_column_with_vocabulary_list将字符串表示为独热矢量,根据明确的词汇表将每个字符串映射到一个整数。
tf.feature_column.categorical_column_with_vocabulary_file将字符串表示为独热矢量,根据文件中的词汇将每个字符串映射到一个整数。
5、经过哈希处理的列
tf.feature_column.categorical_column_with_hash_bucket将类别数量非常大的特征列,模型会计算输入的哈希值,然后使用模运算符将其置于其中一个hash_bucket_size类别中。
6、特征组合列
tf.feature_column.categorical_column_with_hash_bucket将任意分类列进行组合,但仅构建hash_bucket_size参数所请求的类别数量。
7、指标列和嵌入列
指标列(tf.feature_column.indicator_column)和嵌入列(tf.feature_column.embedding_column)将分类列视为输入。