File:Suomen ensimmainen koronavirus aalto kevat 22 ja logistinen kayra ennuste 1.svg
Original file (SVG file, nominally 838 × 491 pixels, file size: 71 KB)
Captions
Summary
[edit]DescriptionSuomen ensimmainen koronavirus aalto kevat 22 ja logistinen kayra ennuste 1.svg |
Suomi: Suomen kevään 2020 koronavirusaallon kasautuneiden koronavirustapausten määrä verrattuna logistiseen käyrään . Näytetapaukset alkavat tässä 15 päivää ennen epidemian alkua ja näytedata ulottuu 60 päivän ajalle. Tämä on epidemian mitassa melko pitkä aikaväli. Tällä perusteella laskettu logistinen käyrä osuu melko lähelle aallon myöhempien koronavirustapausten todellista määrää.
English: First COVID-19 wave in Finland and logistic curve prediction. Eamined cases span day -15 from first case of epidemy. Base data for predition spans 60 days. Prediction is simple logistic curve. |
Date | |
Source | Own work |
Author | Merikanto |
Python code to produce this image
- cumulative covid-19 cases and
- attempt to predict ca. 2 months old wave with logistic curve
- 12.1.2021
- 0000.0001
-
import numpy as np
import numpy.random as npr
import matplotlib.pyplot as plt
from scipy.optimize import leastsq
import math as math
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import locale
from datetime import datetime, timedelta
import matplotlib.dates as mdates
from statsmodels.nonparametric.kernel_regression import KernelReg
from scipy.signal import savgol_filter
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
AutoMinorLocator)
def logistic4(x, A, B, C, D):
"""4PL lgoistic equation."""
return ((A-D)/(1.0+((x/C)**B))) + D
def residuals(p, y, x):
"""Deviations of data from fitted 4PL curve"""
A,B,C,D = p
err = y-logistic4(x, A, B, C, D)
return err
def peval(x, p):
"""Evaluated value at x with current parameters."""
A,B,C,D = p
return logistic4(x, A, B, C, D)
dfin = pd.read_csv('https://datahub.io/core/covid-19/r/countries-aggregated.csv', parse_dates=['Date'])
countries = ['Finland']
dfin = dfin[dfin['Country'].isin(countries)]
selected_columns = dfin"Date", "Confirmed", "Recovered", "Deaths"
df2 = selected_columns.copy()
df2.to_csv (r'kovadata1.csv', index = True, header=True, sep=';')
df = pd.read_csv(r'kovadata1.csv', delimiter=';')
len1=len(df["Date"])
aktiv2= [None] * len1
for n in range(0,len1-1):
aktiv2[n]=0
dates=df['Date']
rekov1=df['Recovered']
konf1=df['Confirmed']
death1=df['Deaths']
dailycases1= [0] * len1
dailydeaths1= [0] * len1
for n in range(1,(len1-1)):
dailycases1[n]=konf1[n]-konf1[n-1]
if (dailycases1[n]<0): dailycases1[n]=0
for n in range(1,(len1-1)):
dailydeaths1[n]=death1[n]-death1[n-1]
if (dailydeaths1[n]<0): dailydeaths1[n]=0
locale.setlocale(locale.LC_TIME, "fi_FI")
dates_a = [datetime.strptime(d,'%Y-%m-%d').date() for d in dates]
dates_aaa = pd.date_range(dates_a[0], periods=len1, freq='1D')
dates_aa=np.array(dates_aaa)
- try to predict covid-19 cases
- logistic distribution
- item to begin specimen
nalku1=20 ## 15 pv ennen 1. tapausta
print ("Alkupvm ", dates_a[nalku1])
konf2=konf1[nalku1:]
dates_b=dates_a[nalku1:]
nayte_alku=0
- length of specimen to
nayte_loppu=60 ## 2 kk
nayte_maara=nayte_loppu-nayte_alku
ennuste_alku=0
ennuste_loppu=175
ennuste_maara=ennuste_loppu-ennuste_alku
x = np.linspace(0,nayte_maara,nayte_maara)
x2=np.linspace(0,ennuste_maara,ennuste_maara)
x3=np.linspace(0,len1,len1)
x4=np.linspace(0,len1-nalku1,len1-nalku1)
dates_c=dates_a[nalku1:nalku1+nayte_maara]
dates_ddd=pd.date_range(dates_c[0], periods=ennuste_maara, freq='1D')
dates_d=np.array(dates_ddd)
A,B,C,D = 0.5,2.5,8,7.3
- y_true = logistic4(x, A, B, C, D)
y_meas=konf2[nayte_alku:nayte_loppu]
y_meas2 = savgol_filter(y_meas, 15, 2)
- Initial guess for parameters
p0 = [0, 1, 1, 1]
- plsq = leastsq(residuals, p0, args=(y_meas, x))
plsq = leastsq(residuals, p0, args=(y_meas2, x))
y2=peval(x2,plsq[0])
- plt.plot(x,y_meas,'bo',x2,y2, "g--", x4,konf2,'r+')
plt.plot(dates_c,y_meas,'ro', dates_aa,konf1,'bx', dates_d,y2, 'g--')
- plt.plot(dates_b,y_meas,'bo', x2,y2, "g--",dates_b,konf2,'r+')
plt.title('Kasautuneet koronavirustapaukset verrattuna logistiseen käyrään', fontsize=12)
- plt.legend()
plt.legend(['Tutkitut tapaukset \n Jakso: alku 15 pv ennen 1. tapausta, \n siitä eteenpäin 60 päivää', 'Todetut tapaukset', 'Ennuste (logistinen käyrä)'], loc='upper left')
- for i, (param, actual, est) in enumerate(zip('ABCD', [A,B,C,D], plsq[0])):
- plt.text(10, 3-i*0.5, '%s = %.2f, est(%s) = %.2f' % (param, actual, param, est))
plt.show()
- plt.savefig('logistic.svg')
Licensing
[edit]- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 17:03, 4 August 2020 | 838 × 491 (71 KB) | Merikanto (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
Metadata
This file contains additional information such as Exif metadata which may have been added by the digital camera, scanner, or software program used to create or digitize it. If the file has been modified from its original state, some details such as the timestamp may not fully reflect those of the original file. The timestamp is only as accurate as the clock in the camera, and it may be completely wrong.
Width | 670.32pt |
---|---|
Height | 392.4pt |