我需要计算多变量RNN LSTM Keras模型的roc曲线。
这是我的数据集
(患者编号,以毫米/秒为单位的时间,X Y和Z的标准化, 分别为峰度,偏度,俯仰,滚动和偏航,标签。
1.15,-0.248010047716,0.00378335508419,-0.0152548459993,-86.3738760481,0.872322164158,-3.51314800063,0
1,31,-0.248010047716,0.00378335508419,-0.0152548459993,-86.3738760481,0.872322164158,-3.51314800063,0
1,46,-0.267422664673,0.0051143782875,-0.0191247001961,-85.7662354031,1.0928406847,-4.08015176908,0
1.62,-0.267422664673,0.0051143782875,-0.0191247001961,-85.7662354031,1.0928406847,-4.08015176908,0
这就是我的尝试:
n = x_train.shape[0]
n2 = x_test.shape[0]
L = 32
X_train_seq = []
Y_train_seq = []
for k in range(n - L + 1):
X_train_seq.append(x_train[k : k + L])
Y_train_seq.append(y_train[k : k + L])
X_test_seq = []
Y_test_seq = []
for k in range(n2 - L + 1):
X_test_seq.append(x_test[k : k + L])
Y_test_seq.append(y_test[k : k + L])
X_train_seq = np.array(X_train_seq)
Y_train_seq = np.array(Y_train_seq)
X_test_seq = np.array(X_test_seq)
Y_test_seq = np.array(Y_test_seq)
model = Sequential()
model.add(LSTM(64, input_shape=(32, 5),
activation='tanh'))
model.add(Dense(32, activation='sigmoid' ))
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
#ROC Curve
y_pred_keras = model.predict(X_test_seq, batch_size = 200).ravel()
fpr_keras, tpr_keras, thresholds_keras = roc_curve(y_test, y_pred_keras)
#AUC
auc_keras = auc(fpr_keras, tpr_keras)
但它给了我以下错误:
ValueError: Found input variables with inconsistent numbers of samples: [502203, 16069504]
另一个问题是我的训练样本是1,415,684,测试是502,203
但是在打印以下x和y的形状时
X_train_seq = np.array(X_train_seq)
Y_train_seq = np.array(Y_train_seq)
X_test_seq = np.array(X_test_seq)
Y_test_seq = np.array(Y_test_seq)
它给我1,415,653个训练和502,172个测试