the difference among pd.factorize, pd.get_dummies, sklearn.preprocessing.LableEncoder and OneHotE...

1.pd.factorize和sklearn.preprocessing.LableEncoder都只接受一维数组输入、一维数组输出;

pd.get_dummies和sklean.preprocessing.OneHotEncoder可接受多维数组输入、多维输出;

2.pd.factorize和sklearn.preprocessing.LableEncoder是编码,不一定搞成one-hot类型的,比如可以将['one','two','three']搞成[1,2,3];


pd.get_dummies和sklean.preprocessing.OneHotEncoder则是搞成one-hot类型编码;


3.pd.get_dummies只能讲categorical数据转成ont-hot形式,数字类型的数据不做任何处理;


A和C列为数字类型,未处理

OneHotEncoder则只能处理数字类型或者字符串类型的数字数据,所以要在使用OneHotEncoder之前需要先用LabelEncoder先将其他categorical data转成int类型


使用OneHotEncoder之前需要先用LabelEncoder先将其他categorical data转成int类型

pandas.factroize和sklean.preprocessing.labelEncoder则是将普通的categorical data(包括int类型的)转成int类型的

你可能感兴趣的:(the difference among pd.factorize, pd.get_dummies, sklearn.preprocessing.LableEncoder and OneHotE...)