LabelEncoder 的使用
作用:将离散型的数据转换成 0 00 到 n − 1 n-1n−1 之间的数,这里 n nn 是一个列表的不同取值的个数,可以认为是某个特征的所有不同取值的个数。from sklearn.preprocessing import LabelEncoderdata = pd.read_csv(pathUtils.train_path,engine='python')encoder= LabelEnc
·
作用:将离散型的数据转换成 0 到 n − 1 之间的数,这里 n 是一个列表的不同取值的个数,可以认为是某个特征的所有不同取值的个数。
from sklearn.preprocessing import LabelEncoder
data = pd.read_csv(pathUtils.train_path,engine='python')
encoder= LabelEncoder().fit(data["job"])
data["job"] = encoder.transform(data["job"])
主要是两个步骤
先构造encoder,通过fit函数传入需要编码的数据,在内部生成对应的key-value
然后encoder 用于需要转化的数据,用transform函数
更多推荐
已为社区贡献3条内容
所有评论(0)