我手头的基本任务是
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))
Run Code Online (Sandbox Code Playgroud)
其中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.
Run Code Online (Sandbox Code Playgroud)
那么每个条目每次都会哈希到完全相同的值吗?
如果不是,有什么好办法可以解决这个问题.有没有办法重新编码编码器的映射?或者与LabelEncoder完全不同的方式?