validation_data=(X_test, Y_test_oh)) # 保存模型 model.save(r'.\model\\' + path + '\\' + str(signal_len) + 's-train_' + str(k + 1) + '-fold.h5py') # 预测 prob_trainY = model.predict(X_train) prob_testY = model.predict(X_test) pred_trainY = np.argmax(prob_trainY, axis=1) pred_testY = np.argmax(prob_testY, axis=1) # 评价指标 Se_tr, Sp_tr, Ber_tr = calc_ber(Y_train, pred_trainY) Se_te, Sp_te, Ber_te = calc_ber(Y_test, pred_testY) Auc_tr = calc_auc(Y_train, np.argmax(prob_trainY, axis=1), 1) Auc_te = calc_auc(Y_test, np.argmax(prob_testY, axis=1), 1) # 绘制代价函数曲线 train_loss = history.history['loss'] test_loss = history.history['val_loss'] train_auc = history.history['auc'] test_auc = history.history['val_auc'] # 保存重要数据 important_data = { 'train_loss': train_loss, 'test_loss': test_loss, 'Se': Se_te, 'Sp': Sp_te,
prob_trainY = model.predict(X_train) prob_testY = model.predict(X_test) # ROC曲线 tpr = Se,fpr = 1-Sp Youden_index = Se+Sp-1 = tpr-fpr(约登指数) fpr, tpr, thresholds = roc_curve(Y_train, prob_trainY, 1, drop_intermediate=False) Youden_index = tpr - fpr # 概率转换成预测标签 thr = thresholds[np.where(Youden_index == np.max(Youden_index))] pred_trainY = (prob_trainY >= thr).astype('int8') pred_testY = (prob_testY >= thr).astype('int8') # 评价指标 Se_tr, Sp_tr, Ber_tr = calc_ber(Y_train, pred_trainY) Se_te, Sp_te, Ber_te = calc_ber(Y_test, pred_testY) Auc_tr = calc_auc(Y_train, prob_trainY, 1) Auc_te = calc_auc(Y_test, prob_testY, 1) # 绘制代价函数曲线 train_loss = history.history['loss'] test_loss = history.history['val_loss'] train_auc = history.history['auc'] test_auc = history.history['val_auc'] # 保存重要数据 important_data = { 'train_loss': train_loss, 'test_loss': test_loss, 'Se': Se_te, 'Sp': Sp_te, 'Auc': Auc_te,