对python 数据处理中的LabelEncoder 和 OneHotEncoder详解
如下所示:
#简单来说LabelEncoder是对不连续的数字或者文本进行编号 fromsklearn.preprocessingimportLabelEncoder le=LabelEncoder() le.fit([1,5,67,100]) le.transform([1,1,100,67,5]) 输出:array([0,0,3,2,1]) #OneHotEncoder用于将表示分类的数据扩维: fromsklearn.preprocessingimportOneHotEncoder ohe=OneHotEncoder() ohe.fit([[1],[2],[3],[4]]) ohe.transform([2],[3],[1],[4]).toarray() 输出:[[0,1,0,0],[0,0,1,0],[1,0,0,0],[0,0,0,1]]
以上这篇对python数据处理中的LabelEncoder和OneHotEncoder详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。