Spaces:
Runtime error
Runtime error
Commit
·
309bec6
1
Parent(s):
c57793a
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,7 @@ from math import sqrt
|
|
9 |
from scipy import stats as st
|
10 |
from matplotlib import pyplot as plt
|
11 |
|
|
|
12 |
from sklearn.calibration import CalibratedClassifierCV
|
13 |
|
14 |
import shap
|
@@ -186,12 +187,29 @@ output_y4 = (
|
|
186 |
|
187 |
|
188 |
#Define predict for y1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
def y1_predict(*args):
|
190 |
df1 = pd.DataFrame([args], columns=x1.columns)
|
191 |
pos_pred = y1_calib_model.predict_proba(df1)
|
192 |
prob = pos_pred[0][1]
|
193 |
-
prob = 1-prob
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
return output
|
196 |
|
197 |
#Define predict for y2.
|
|
|
9 |
from scipy import stats as st
|
10 |
from matplotlib import pyplot as plt
|
11 |
|
12 |
+
from sklearn.utils import resample
|
13 |
from sklearn.calibration import CalibratedClassifierCV
|
14 |
|
15 |
import shap
|
|
|
187 |
|
188 |
|
189 |
#Define predict for y1.
|
190 |
+
def bootstrap_ci(data, model, alpha=0.05):
|
191 |
+
"""Compute bootstrap confidence intervals"""
|
192 |
+
bootstrapped_probs = [model.predict_proba(resample(data))[0][1] for _ in range(1000)]
|
193 |
+
lower = np.percentile(bootstrapped_probs, 100*(alpha/2.0))
|
194 |
+
upper = np.percentile(bootstrapped_probs, 100*(1-alpha/2.0))
|
195 |
+
return lower, upper
|
196 |
+
|
197 |
def y1_predict(*args):
|
198 |
df1 = pd.DataFrame([args], columns=x1.columns)
|
199 |
pos_pred = y1_calib_model.predict_proba(df1)
|
200 |
prob = pos_pred[0][1]
|
201 |
+
prob = 1 - prob
|
202 |
+
lower, upper = bootstrap_ci(df1, y1_calib_model)
|
203 |
+
output = (
|
204 |
+
f"""
|
205 |
+
<br/>
|
206 |
+
<center>The probability of 6-month survival:</center>
|
207 |
+
<br/>
|
208 |
+
<center><h1>{prob:.2f}%</h1></center>
|
209 |
+
<br/>
|
210 |
+
<center>95% Confidence Interval: [{lower:.2f}%, {upper:.2f}%]</center>
|
211 |
+
"""
|
212 |
+
)
|
213 |
return output
|
214 |
|
215 |
#Define predict for y2.
|