前提
PythonでSEIRモデルの微分方程式を解いています。
実現したいこと
新型コロナウイルスの新規感染者の過去のデータを最小二乗法を用いてフィッティングを行なっています。
発生している問題・エラーメッセージ
発生している問題は最小二乗法で過去のデータに当てはめた曲線を導出したのですが最小の方でグラフが曲がって出てしまいました。緩やかな曲線で導出したいのでここを緩やかにするためにはどのようにするべきかお聞きしたいです。
該当のソースコード
Python
1import numpy as np 2import matplotlib.pyplot as plt 3from scipy.integrate import odeint 4from scipy import optimize 5import csv 6 7# loading csv-file 8f = open("./COVID_3nd_wave.csv", "r", encoding="UTF-8", errors="", newline="" ) 9fcsv = csv.reader(f, delimiter=",", doublequote=True, lineterminator="\r\n", quotechar='"', skipinitialspace=True) 10 11next(f) # skip to the header of the csv-file 12 13cases = [] 14for row in fcsv: 15 cases.append(int(row[1])) 16 17Tokyo = 13999568 # the population of Tokyo in 2020 18normalized_cases = np.array(cases, dtype = float)/Tokyo 19days = len(cases) 20t = np.arange(days) 21# initial values 22I0 = normalized_cases[0]; S0 = 1.0 - I0; E0 = 0.0; R0 = 0.0 23 24# SIR differential equation 25# S = SEIR[0], E = SEIR[1], I = SEIR[2], R = SEIR[3] 26def SEIReq(SEIR, t, beta, ipusilon, gamma): 27 dSdt = -beta*SEIR[0]*SEIR[2] 28 dEdt = beta*SEIR[0]*SEIR[2] - ipusilon*SEIR[1] 29 dIdt = ipusilon*SEIR[1] - gamma*SEIR[2] 30 dRdt = gamma*SEIR[2] 31 32 return [dSdt, dEdt, dIdt, dRdt] 33 34def I(t, beta, ipusilon, gamma): 35 SEIRlist = odeint(SEIReq, (S0, E0, I0, R0), t, args = (beta, ipusilon, gamma)) 36 return SEIRlist[:,2] 37 38p0 = [10, 10, 10] 39optparams, cov = optimize.curve_fit(I, t, normalized_cases, p0) 40print('R0=',optparams[0]/optparams[2]) 41print(optparams[0]) 42print(optparams[1]) 43print(optparams[2]) 44fitted = I(t, *optparams) 45 46plt.scatter(t, cases) 47plt.plot(t, fitted*Tokyo) 48plt.xlabel('the number of days from 2020/7/15') 49plt.ylabel('the number of confirmed cases in Tokyo') 50plt.show() 51f.close() # close the csv-file
試したこと
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
csvファイルは写真のようになっています。2020年は12月1日〜2021年2月7日の厚生労働省のオープンデータとなっています。

あなたの回答
tips
プレビュー