用 plot_roc_curve(svc, X_test, y_test) 画的ROC曲线中AUC为0.94
但是,用下面的代码计算的95%CI为array([0.91081856, 0.94210099])
def bootstrap_auc(svc, X_train, y_train, X_test, y_test, nsamples=100):
auc_values = []
for b in range(nsamples):
idx = np.random.randint(X_train.shape[0], size=X_train.shape[0])
svc.fit(X_train.iloc[idx], y_train.iloc[idx])
pred = svc.predict_proba(X_test)[:, 1]
roc_auc = roc_auc_score(y_test.ravel(), pred.ravel())
auc_values.append(roc_auc)
return np.percentile(auc_values, (2.5, 97.5))
bootstrap_auc(svc, X_train, y_train, X_test, y_test, nsamples=100)