np.mean(
        multilabel_auc(
            pd.get_dummies(perch.test['labels']).values, pred_all[i]))
    for i in range(18)
]
# aggregate prediction
pred_stacked = np.stack(pred_all)

pred_ensemble_arbitrators = pred_stacked[14:, :, :].mean(axis=0)
pred_ensemble = pred_stacked.mean(axis=0)
pred_ensemble_weighted = np.average(pred_stacked,
                                    axis=0,
                                    weights=np.array(rev_weights))
accuracy = multiclass_acc(
    pd.get_dummies(perch.test['labels']).values, pred_ensemble)
accuracy_consolidation_infiltrates = consolidation_infiltrates_acc(
    pd.get_dummies(perch.test['labels']).values, pred_ensemble)
accuracy_arbitrators = multiclass_acc(
    pd.get_dummies(perch.test['labels']).values, pred_ensemble_arbitrators)
accuracy_weighted = multiclass_acc(
    pd.get_dummies(perch.test['labels']).values, pred_ensemble_weighted)
auc = np.mean(
    multilabel_auc(pd.get_dummies(perch.test['labels']).values, pred_ensemble))
auc_weighted = np.mean(
    multilabel_auc(
        pd.get_dummies(perch.test['labels']).values, pred_ensemble_weighted))
auc_arbitrators = np.mean(
    multilabel_auc(
        pd.get_dummies(perch.test['labels']).values,
        pred_ensemble_arbitrators))
save_table3(method="Supervised Pretraining - Ensemble",
            chestray=with_chestray,
Exemple #2
0
model.set_weights(weights_swa)
pred_ens_swa = model.predict(ds_test)

pred_ens_stacked = pred_ens.mean(axis=0)
sep_ens_acc = [
    multiclass_acc(labs_test, pred_ens[i, :, :])
    for i in range(pred_ens.shape[0])
]
sep_ens_auc = [
    np.mean(multilabel_auc(labs_test, pred_ens[i, :, :]))
    for i in range(pred_ens.shape[0])
]

auc = np.mean(multilabel_auc(labs_test, pred_ens_stacked))
acc = multiclass_acc(labs_test, pred_ens_stacked)
cons_infil_scores = consolidation_infiltrates_acc(labs_test, pred_ens_stacked)

multilabel_auc(labs_test, pred_ens_swa)
multiclass_acc(labs_test, pred_ens_swa)

if display:
    perch_confusion_matrix(labs_test.argmax(axis=1),
                           pred_ens_stacked.argmax(axis=1))

save_table3(method="Supervised Pretraining",
            chestray=with_chestray,
            model=basemodel.name,
            accuracy=acc,
            auc=auc,
            details=details_,
            other=json.dumps({'acc_cons_infil': cons_infil_scores}))