1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| import numpy as np import matplotlib.pyplot as plt import math import pandas as pd import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit def logistic_increase_function(t,K,P0,r): t0=11 r = 0.45 exp_value=np.exp(r*(t-t0)) return (K*exp_value*P0)/(K+(exp_value-1)*P0) ''' 1.11日41例 1.18日45例 1.19日62例 1.20日291例 1.21日440例 1.22日571例 1.23日835例 1.24日1297例 1.25日1985例 1.26日2762例 1.27日4535例 '''
t=[11,18,19,20 ,21, 22, 23, 24, 25, 26, 27] t=np.array(t) P=[41,45,62,291,440,571,835,1297,1985,2762,4535] P=np.array(P)
popt1, pcov1 = curve_fit(logistic_increase_function, t, P)
print("K:capacity P0:initial_value r:increase_rate t:time") print(popt1)
P_predict = logistic_increase_function(t,popt1[0],popt1[1],popt1[2])
future=[11,18,19,20 ,21, 22, 23, 24, 25, 26, 27,28,29,30,31,41,51,61,71,81,91,101] future=np.array(future) future_predict=logistic_increase_function(future,popt1[0],popt1[1],popt1[2])
tomorrow=[28,29,30,32,33,35,37,40] tomorrow=np.array(tomorrow) tomorrow_predict=logistic_increase_function(tomorrow,popt1[0],popt1[1],popt1[2])
plot1 = plt.plot(t, P, 's',label="confimed infected people number") plot2 = plt.plot(t, P_predict, 'r',label='predict infected people number') plot3 = plt.plot(tomorrow, tomorrow_predict, 's',label='tomorrow predict infected people number') plt.xlabel('time')
plt.ylabel('confimed infected people number') plt.legend(loc=0) print(logistic_increase_function(np.array(28),popt1[0],popt1[1],popt1[2])) print(logistic_increase_function(np.array(29),popt1[0],popt1[1],popt1[2])) plt.show()
|