更新时间:2023-12-02 14:52:40
首先,您需要通过
将y_train
转换为单编码
First, you need to convert y_train
to one-hot encoding by
from sklearn.preprocessing import LabelEncoder
from keras.utils import np_utils
encoder = LabelEncoder()
encoder.fit(y_train)
encoded_y = encoder.transform(y_train)
y_train = np_utils.to_categorical(encoded_y)
运行此代码,y_train
将变为
array([[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[1., 0.],
[0., 1.],
[0., 1.],
[0., 1.],
[0., 1.]], dtype=float32)
第二,您需要将输出层更改为
Secondly, you need to change the output layer to
model.add(Dense(2, activation='softmax'))
通过这两个修改,您将获得所需的输出.
with these two modifications, you will get the desired output.