我正在为期末考试建立两个神经网络模型(二进制分类)。我有混淆矩阵作为评估,但它总是给我一个标签输出。
有人能看出我在哪里犯了错吗?下面是代码:
# Start neural network
network = Sequential()
# Add fully connected layer with a ReLU activation function
network.add(Dense(units=2, activation='relu', input_shape=(2,)))
# Add fully connected layer with a ReLU activation function
network.add(Dense(units=4, activation='relu'))
# Add fully connected layer with a sigmoid activation function
network.add(Dense(units=1, activation='sigmoid'))
# Compile neural network
network.compile(loss='binary_crossentropy', # Cross-entropy
optimizer='rmsprop', # Root Mean Square Propagation
metrics=['accuracy']) # Accuracy performance metric
# Train neural network
history = network.fit(X_train, # Features
y_train, # Target vector
epochs=3, # Number of epochs
verbose=1, # Print description after each epoch
batch_size=10, # Number of observations per batch
validation_data=(X_val, y_val)) # Data for evaluation
y_pred = network.predict(X_test)
# y_test = y_test.astype(int).tolist()
y_pred = np.argmax(y_pred, axis=1).tolist()
cm = confusion_matrix(y_test, y_pred)
print(cm)我从验证中获得了93%的准确性,但是混淆矩阵给了我这个输出:

发布于 2022-08-01 21:49:09
您的网络只有一个乙状结肠输出,这意味着为了获得您的分类,您希望圆形您的结果,而不是一个argmax。
y_pred = np.round(y_pred).tolist()如果要打印您的y_pred,您会注意到它是Nx1矩阵,因此argmax对每一行返回0(因为这是唯一的列)。
https://stackoverflow.com/questions/73199505
复制相似问题