为了对sex
等分类数据进行编码,我们通常在scikit learn
中使用LabelEncorder()
。但是,如果我要使用 Tensorflow
而不是 Scikit Learn
,执行此类任务的等效函数或方法是什么?我知道我们可以使用 tensorflow
轻松进行一个热编码
,但随后它将创建标签为 10
、 01
> 而不是 1
, 0
。
最佳答案
TensorFlow中有一个名为tf.feature_columns的包,其中包含 4 种从输入数据创建分类列的方法:
- categorical_column_with_hash_bucket(...):将输入值哈希到固定数量的类别
- categorical_column_with_identity(...):如果您有数字输入并且希望将值本身视为分类列
- categorical_column_with_vocabulary_list(...):根据固定(内存)单词列表输出类别
- categorical_column_with_vocabulary_file(...):与 _list 相同,但从文件中读取词汇表
该包还提供了更多将输入数据输入模型的方法。有关概述,请参阅此 blogpost由包的开发人员编写。
关于tensorflow - sklearn.preprocessing 中的 LabelEncoder 是否有类似的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48459222/