【发布时间】:2015-04-23 18:29:21
【问题描述】:
我手头的基本任务是
a) 读取一些制表符分隔的数据。
b) 做一些基本的预处理
c) 对于每个分类列,使用LabelEncoder 创建一个映射。这有点像这样
mapper={}
#Converting Categorical Data
for x in categorical_list:
mapper[x]=preprocessing.LabelEncoder()
for x in categorical_list:
df[x]=mapper[x].fit_transform(df.__getattr__(x))
其中df 是pandas 数据框,categorical_list 是需要转换的列标题列表。
d) 使用 pickle 训练分类器并将其保存到磁盘
e) 现在在另一个程序中,保存的模型被加载。
f) 加载测试数据并执行相同的预处理。
g) LabelEncoder's 用于转换分类数据。
h) 模型用于预测。
现在我的问题是,g) 步骤会正常工作吗?
正如LabelEncoder 的文档所述
It can also be used to transform non-numerical labels (as long as
they are hashable and comparable) to numerical labels.
那么每个条目每次都会散列到完全相同的值吗?
如果否,有什么好的方法可以解决这个问题。有什么方法可以检索编码器的映射?还是与 LabelEncoder 完全不同的方式?
【问题讨论】:
-
你可以试试这个,但是这个想法是哈希对于相同的输入是相同的
-
为什么不腌制这些
mappers? -
我试过...它只是转储 {}...我如何获得这些键值对??
标签: python pandas scikit-learn