版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_24671941/article/details/84110737
代码:
# coding:utf-8
from sklearn.preprocessing import LabelEncoder
from keras.utils import np_utils
# 7种车的名字
y_train = ['Chevrolet', 'Audi', 'Lexus', 'Toyota', 'Maserati', 'Lancia', 'Renault']
print y_train
# 将字符串转为数值型
y_train = LabelEncoder().fit_transform(y_train)
print y_train
# 将普通数值型转为onehot编码
y_train = np_utils.to_categorical(y_train)
print y_train
运行结果: