-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
86 lines (52 loc) · 2.31 KB
/
main.py
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
import pandas as pd
from fbprophet import Prophet
from fbprophet.plot import add_changepoints_to_plot
from fbprophet.diagnostics import cross_validation
from fbprophet.diagnostics import performance_metrics
from fbprophet.plot importplot_cross_validation_metric
'''Reading CSV file from covid19 clean complete file location'''
df=pd.read_csv(r':/file_location/covid_19_clean_complete.csv')
# print(df.head())
# print(df.shape)
# print(df.dtypes)
'''Converting df['Date'] type from object to date time'''
df['Date']=pd.to_datetime(df['Date'])
# print(df.dtypes)
# print(df.isnull().sum())
# print(df['Date'].nunique())
# print(df.shape)
'''Grouping the covid19 cases(confirmed,active,deaths,recovered)'''
total=df.groupby(['Date'])['Confirmed','Deaths','Active','Recovered'].sum().reset_index()
# print(total.head())
'''Renaming the columns as 'ds' and 'y' since the documentation says default columns names'''
df_prophet=total.rename(columns={'Date':'ds','Confirmed':'y'})
'''initializing prophet model'''
m=Prophet()
'''fitting the data into the model'''
model=m.fit(df_prophet)
print(model.seasonalities)
'''taking a 30 days future prediction with current model'''
future_global=model.make_future_dataframe(periods=30,freq='D')
# print(future_global.head())
# print(future_global.shape)
'''predicting the future 30days data'''
prediction = model.predict(future_global)
# print(prediction)
print(prediction[['ds','yhat','yhat_lower','yhat_upper']].tail())
'''plotting the predicted model graph(make as exponential)'''
model.plot(prediction)
model.plot_components(prediction)
fig=model.plot(prediction)
a=add_changepoints_to_plot(fig.gca(),model,prediction)
'''checking the cross validation of the predicted model'''
df_cv=cross_validation(model,horizon='30 days',period='15 days',initial='90 days')
# print(df_cv.head())
# print(df_cv.shape)
'''checking the performance metrics of the cross validated predicted model'''
df_performance = performance_metrics(df_cv)
# print(df_performance.head())
df_performance = plot_cross_validation_metric(df_cv,metric='rmse')
df_performance = plot_cross_validation_metric(df_cv,metric='mse')
df_performance = plot_cross_validation_metric(df_cv,metric='mae')
df_performance = plot_cross_validation_metric(df_cv,metric='mape')
df_performance = plot_cross_validation_metric(df_cv,metric='mdape')