1 python中one-hot总结
先通过LabelEncoder()将分类变量转化成整数形式,然后通过OneHotEncoder()将数据转换成矩阵的形式。
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
label_encoder= LabelEncoder()
integer_encoded = label_encoder.fit_transform(values)
onehot_encoder = OneHotEncoder(sparse=False)
one_hot_df = pd.DataFrame(onehot_encoder.fit_transform(integer_encoded .reshape(-1,1)))
网友评论