import json
from datetime import date
import matplotlib.pyplot as plt
import numpy as np
import requests
from scipy.stats import binom
= json.dumps(
data
{"horizon_dt": date.today().strftime("%Y-%m-%dT%H:%M:%S.%f"),
"department": "gwb",
} )
ICU aggregate probabilities
= requests.post("http://uclvlddpragae08:5219/predict/", data).json()
elective_preds = requests.post("http://uclvlddpragae08:5230/predict/", data).json() nonelective_preds
= []
elective for bed_num in elective_preds["data"]:
"probability"])
elective.append(bed_num[print(
"If the number of elective patients on list is " + str(len(elective) - 1),
"the ML model will return a set of predictions from 0 beds, needed, up to that maximum, so our first array has "
+ str(len(elective))
+ " values, starting with zero",
)= list(range(0, len(elective)))
poss_beds print(poss_beds)
= plt.subplots(1, 1)
fig, ax
plt.scatter(poss_beds, elective)"Distribution of elective probabilities")
plt.title( plt.show()
= []
nonelective for bed_num in nonelective_preds["data"]:
"probability"])
nonelective.append(bed_num[print(
"The ML model will return predictions for a set of beds needed for nonelective patients that might arrive ranging from 0 to "
+ str(len(nonelective) - 1),
" so our second array has " + str(len(nonelective)) + " values, starting with zero",
)= list(range(0, len(nonelective)))
poss_beds print(poss_beds)
= plt.subplots(1, 1)
fig, ax
plt.scatter(poss_beds, nonelective)"Distribution of nonelective probabilities")
plt.title( plt.show()
= 18
num_on_unit = 0.8
prob_still_here = binom.pmf(list(range(0, num_on_unit + 1)), num_on_unit, prob_still_here)
onunit print(
"Let's say there are "
+ str(num_on_unit)
+ " already on the unit each with a probability of "
+ str(prob_still_here)
+ " of still being here in 24 hours time, so our third array has "
+ str(len(onunit))
+ " values, starting with zero"
)= list(range(0, len(onunit)))
poss_beds print(poss_beds)
= plt.subplots(1, 1)
fig, ax
plt.scatter(poss_beds, onunit)"Distribution of probabilities for pats on unit")
plt.title( plt.show()
print(
"The total possible number of admissions is the sum of the maximum possible from each of these separate distributions, which is "
+ str(num_on_unit + len(elective) - 1 + len(nonelective) - 1),
"so the length of our aggregated predictions is one more than this number, as it is starting at zero",
)= list(range(0, len(onunit) + len(elective) - 1 + len(nonelective) - 1))
tot_beds_array print(tot_beds_array)
print(
"To get a probability distribution over all these, we simply convolve them together like this: "
)= np.convolve(onunit, np.convolve(elective, nonelective)) aggregated
= plt.subplots(1, 1)
fig, ax
plt.scatter(tot_beds_array, aggregated)"Distribution of aggregated probabilities")
plt.title( plt.show()