pandas LabelEncoder方法,对离散值进行编码,并储存
# 3.离散值进行LabelEncoder #处理数据的三个步骤,去重,处理缺失值,离散值LabelEncoder
from sklearn import preprocessing
from sklearn.externals import joblib
categorical_ix = ["1","2","3"] #离散值的列名 for i in categorical_ix: le = preprocessing.LabelEncoder() k = le.fit_transform(df_train[i]) joblib.dump(le,i+"_LabelEncoder.model") df_train[i] = k for i in categorical_ix: le = joblib.load(i+"_LabelEncoder.model") k = le.transform(df_train[i]) df_test[i] = k