使用单个数据点时仅从 Model.Predict() 获取零,但使用整个测试数据集时获取 1 和 0

Getting Only Zeros from Model.Predict() When Using Individual Data Points But Getting both 1's and 0's when Using Entire Test Dataset

我们以 ~90% 的准确率/~20% 的损失训练了一个二元分类 nn。当我们通过使用测试数据(占整个数据集的 20%)调用 model.predict() 函数来使用模型时,我们得到相对均匀分布的 1 和 0。但是,当我们将测试数据中的各个点作为 numpy 数组输入时,无论是否进行混洗,我们都只会得到 0。谁能帮我们解释为什么会出现这种行为?

当我们使用 X_test(来自上面的拆分)而不是 dummyTest 时,binary_prediction 对来自 dummyTest 的相应数据点数组等于 1),但是当我们单独使用dummyTest的数据,binary_prediction只等于0。

完整代码如下所示:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pandas.plotting import scatter_matrix
from sklearn import model_selection
from keras.utils.np_utils import to_categorical
from keras.models import Sequential
from keras.layers import Dense
from tensorflow.keras.optimizers import Adam
from keras.layers import Dropout
import os

full_dataset = pd.read_csv('noQMarkDataset.csv')
data = full_dataset[~full_dataset.isin(['?'])]
data = data.dropna(axis=0)
data = data.apply(pd.to_numeric)

X = np.array(data.drop(['target'], 1))
y = np.array(data['target'])

mean = X.mean(axis=0)
X -= mean
std = X.std(axis=0)
X /= std

X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, random_state = 0, test_size = 0.2, shuffle=False)  #stratify = y

# convert data to categorical labels
Y_train = to_categorical(y_train, num_classes=None)
Y_test = to_categorical(y_test, num_classes=None)

Y_train_binary = y_train.copy()
Y_test_binary = y_test.copy()

Y_train_binary[Y_train_binary > 0] = 1
Y_test_binary[Y_test_binary > 0] = 1

def create_binary_model():
    model = Sequential()
    model.add(Dense(16, input_dim=7,  activation='relu')) # prev input_dim =1 3
    model.add(Dropout(0.25))
    model.add(Dense(16,  activation = 'relu'))
    model.add(Dropout(0.25))
    model.add(Dense(16))
    model.add(Dropout(0.25))
    model.add(Dense(12, activation = 'relu'))
    model.add(Dense(12, activation = 'relu'))
    model.add(Dropout(0.25))
    model.add(Dense(8,  activation='relu'))
    model.add(Dropout(0.25))
    model.add(Dense(1, activation='sigmoid'))

    adam = Adam(lr=0.001)
    model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])       #optimizer = 'rmsprop'  previously 
    
    return model

binary_model = create_binary_model()
history=binary_model.fit(X_train, Y_train_binary, validation_data=(X_test, Y_test_binary), epochs=130, batch_size=15)   #epochs = 130, batch_size = 20 previously (best)

plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Model Accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['train', 'test'])
plt.show()

plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('Model Loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'test'])
plt.show()

from sklearn.metrics import classification_report, accuracy_score
dummyTest = np.array([[67.0,1.0,4.0,0.0,2.0,129.0,2.0]])
binary_pred = np.round(binary_model.predict(dummyTest)).astype(int) 
#binary_pred = np.round(binary_model.predict(X_test)).astype(int)
print(f"Binary Pred: {binary_pred}")

binary_model.save(os.path.join(".", "test_model.h5"))

#after loading
from tensorflow.keras.models import load_model
model2 = load_model(os.path.join(".", "test_model.h5"))
binary_pred2 = np.round(binary_model.predict(dummyTest)).astype(int) 
#binary_pred2 = np.round(binary_model.predict(X_test)).astype(int)
print(f"Binary Pred2 after load: {binary_pred2}")

完整数据集如下所示

age,sex,cp,fbs,restecg,thalach,ca,target
63.0,1.0,1.0,1.0,2.0,150.0,0.0,0
67.0,1.0,4.0,0.0,2.0,108.0,3.0,2
67.0,1.0,4.0,0.0,2.0,129.0,2.0,1
37.0,1.0,3.0,0.0,0.0,187.0,0.0,0
41.0,0.0,2.0,0.0,2.0,172.0,0.0,0
56.0,1.0,2.0,0.0,0.0,178.0,0.0,0
62.0,0.0,4.0,0.0,2.0,160.0,2.0,3
57.0,0.0,4.0,0.0,0.0,163.0,0.0,0
63.0,1.0,4.0,0.0,2.0,147.0,1.0,2
53.0,1.0,4.0,1.0,2.0,155.0,0.0,1
57.0,1.0,4.0,0.0,0.0,148.0,0.0,0
56.0,0.0,2.0,0.0,2.0,153.0,0.0,0
56.0,1.0,3.0,1.0,2.0,142.0,1.0,2
44.0,1.0,2.0,0.0,0.0,173.0,0.0,0
52.0,1.0,3.0,1.0,0.0,162.0,0.0,0
57.0,1.0,3.0,0.0,0.0,174.0,0.0,0
48.0,1.0,2.0,0.0,0.0,168.0,0.0,1
54.0,1.0,4.0,0.0,0.0,160.0,0.0,0
48.0,0.0,3.0,0.0,0.0,139.0,0.0,0
49.0,1.0,2.0,0.0,0.0,171.0,0.0,0
64.0,1.0,1.0,0.0,2.0,144.0,0.0,0
58.0,0.0,1.0,1.0,2.0,162.0,0.0,0
58.0,1.0,2.0,0.0,2.0,160.0,0.0,1
58.0,1.0,3.0,0.0,2.0,173.0,2.0,3
60.0,1.0,4.0,0.0,2.0,132.0,2.0,4
50.0,0.0,3.0,0.0,0.0,158.0,0.0,0
58.0,0.0,3.0,0.0,0.0,172.0,0.0,0
66.0,0.0,1.0,0.0,0.0,114.0,0.0,0
43.0,1.0,4.0,0.0,0.0,171.0,0.0,0
40.0,1.0,4.0,0.0,2.0,114.0,0.0,3
69.0,0.0,1.0,0.0,0.0,151.0,2.0,0
60.0,1.0,4.0,1.0,0.0,160.0,2.0,2
64.0,1.0,3.0,0.0,0.0,158.0,0.0,1
59.0,1.0,4.0,0.0,0.0,161.0,0.0,0
44.0,1.0,3.0,0.0,0.0,179.0,0.0,0
42.0,1.0,4.0,0.0,0.0,178.0,0.0,0
43.0,1.0,4.0,0.0,2.0,120.0,0.0,3
57.0,1.0,4.0,0.0,2.0,112.0,1.0,1
55.0,1.0,4.0,0.0,0.0,132.0,1.0,3
61.0,1.0,3.0,1.0,0.0,137.0,0.0,0
65.0,0.0,4.0,0.0,2.0,114.0,3.0,4
40.0,1.0,1.0,0.0,0.0,178.0,0.0,0
71.0,0.0,2.0,0.0,0.0,162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,174.0,0.0,0
61.0,1.0,4.0,0.0,0.0,161.0,1.0,2
58.0,1.0,4.0,0.0,1.0,140.0,3.0,4
58.0,0.0,4.0,1.0,2.0,146.0,2.0,2
56.0,1.0,2.0,0.0,2.0,163.0,0.0,0
56.0,1.0,2.0,0.0,0.0,169.0,0.0,0
67.0,1.0,3.0,0.0,2.0,150.0,0.0,1
55.0,0.0,2.0,0.0,0.0,166.0,0.0,0
44.0,1.0,4.0,0.0,0.0,144.0,0.0,2
63.0,1.0,4.0,0.0,2.0,144.0,2.0,2
63.0,0.0,4.0,0.0,0.0,136.0,0.0,1
41.0,1.0,2.0,0.0,0.0,182.0,0.0,0
59.0,1.0,4.0,1.0,2.0,90.0,2.0,3
57.0,0.0,4.0,0.0,0.0,123.0,0.0,1
45.0,1.0,1.0,0.0,0.0,132.0,0.0,1
68.0,1.0,4.0,1.0,0.0,141.0,2.0,2
57.0,1.0,4.0,0.0,0.0,115.0,1.0,3
57.0,0.0,2.0,0.0,2.0,174.0,1.0,1
66.0,0.0,3.0,0.0,2.0,152.0,1.0,0
39.0,0.0,3.0,0.0,0.0,152.0,0.0,0
57.0,1.0,2.0,0.0,2.0,164.0,1.0,1
58.0,0.0,4.0,0.0,0.0,131.0,0.0,0
57.0,1.0,4.0,0.0,0.0,143.0,1.0,2
47.0,1.0,3.0,0.0,0.0,179.0,0.0,0
55.0,0.0,4.0,0.0,1.0,130.0,1.0,3
35.0,1.0,2.0,0.0,0.0,174.0,0.0,0
61.0,1.0,4.0,0.0,0.0,161.0,1.0,2
58.0,1.0,4.0,0.0,1.0,140.0,3.0,4
46.0,1.0,4.0,0.0,0.0,120.0,2.0,2
71.0,0.0,4.0,0.0,0.0,125.0,0.0,0
59.0,1.0,1.0,0.0,0.0,162.0,2.0,1
64.0,1.0,1.0,0.0,2.0,155.0,0.0,0
66.0,0.0,3.0,0.0,2.0,152.0,1.0,0
39.0,0.0,3.0,0.0,0.0,152.0,0.0,0
57.0,1.0,2.0,0.0,2.0,164.0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,1
61.0,1.0,4.0,0.0,0.0,140.0,1.0,2
39.0,1.0,4.0,0.0,0.0,140.0,0.0,3
61.0,0.0,4.0,0.0,2.0,146.0,0.0,1
56.0,1.0,4.0,1.0,2.0,144.0,1.0,1
52.0,1.0,1.0,0.0,2.0,190.0,0.0,0
43.0,0.0,4.0,1.0,2.0,136.0,0.0,2
67.0,1.0,4.0,0.0,2.0,108.0,3.0,2
67.0,1.0,4.0,0.0,2.0,129.0,2.0,1
37.0,1.0,3.0,0.0,0.0,187.0,0.0,0
41.0,0.0,2.0,0.0,2.0,172.0,0.0,0
56.0,1.0,2.0,0.0,0.0,178.0,0.0,0
62.0,0.0,4.0,0.0,2.0,160.0,2.0,3
57.0,0.0,4.0,0.0,0.0,163.0,0.0,0
63.0,1.0,4.0,0.0,2.0,147.0,1.0,2
53.0,1.0,4.0,1.0,2.0,155.0,0.0,1
57.0,1.0,4.0,0.0,0.0,148.0,0.0,0
56.0,0.0,2.0,0.0,2.0,153.0,0.0,0
56.0,1.0,3.0,1.0,2.0,142.0,1.0,2
44.0,1.0,2.0,0.0,0.0,173.0,0.0,0
52.0,1.0,3.0,1.0,0.0,162.0,0.0,0
57.0,1.0,3.0,0.0,0.0,174.0,0.0,0
48.0,1.0,2.0,0.0,0.0,168.0,0.0,1
54.0,1.0,4.0,0.0,0.0,160.0,0.0,0
48.0,0.0,3.0,0.0,0.0,139.0,0.0,0
50.0,1.0,2.0,0.0,0.0,160.0,0.0,0
54.0,0.0,2.0,0.0,0.0,150.0,1.0,0
54.0,0.0,2.0,0.0,1.0,155.0,1.0,0
54.0,0.0,2.0,0.0,0.0,130.0,1.0,0
54.0,0.0,2.0,0.0,0.0,130.0,1.0,0
54.0,1.0,1.0,0.0,0.0,137.0,1.0,0
54.0,1.0,2.0,0.0,0.0,142.0,1.0,0
54.0,1.0,2.0,0.0,0.0,154.0,1.0,0
54.0,1.0,2.0,0.0,0.0,110.0,1.0,0
54.0,1.0,2.0,0.0,1.0,130.0,1.0,0
59.0,1.0,4.0,0.0,0.0,140.0,0.0,0
47.0,1.0,4.0,0.0,0.0,98.0,0.0,1
56.0,1.0,4.0,0.0,0.0,120.0,0.0,1
59.0,1.0,4.0,0.0,1.0,131.0,0.0,0

您正在使用规范化数据训练模型,但对未规范化的数据进行预测。 X_test 是归一化数据,因此对它的预测符合预期。 dummyTest 未标准化。如果您在将 dummyTest 变量输入神经网络之前对其进行归一化,如下所示:

dummyTest[0] -= mean
dummyTest[0] /= std

您将收到预期的输出(1)