<jupyter_start><jupyter_text>Prediction Of Covid Cases Using FbProphet<jupyter_code>!pip install pystan
!pip install fbprophet
import fbprophet
from fbprophet import Prophet
import pandas as pd
df=pd.read_csv('/content/covid_19_clean_complete.csv')
df.head()
import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Top 5 Countries ranked by Covid Deaths<jupyter_code>total_deaths=df.groupby(['Country/Region'])['Deaths'].sum().reset_index()
total_deaths.sort_values('Deaths',ascending=False,inplace=True)
total_deaths = total_deaths.head()
sns.barplot(x=total_deaths['Country/Region'],y=total_deaths['Deaths'])<jupyter_output><empty_output><jupyter_text>Top 5 Countries ranked by Recovered Covid Cases<jupyter_code>total_Recovered=df.groupby(['Country/Region'])['Recovered'].sum().reset_index()
total_Recovered.sort_values('Recovered',ascending=False,inplace=True)
total_Recovered = total_Recovered.head()
sns.barplot(x=total_Recovered['Country/Region'],y=total_Recovered['Recovered'])
df.shape
df.dtypes
df['Date']=pd.to_datetime(df['Date'])
df.dtypes
df.isnull().sum()
df['Date'].nunique()
total=df.groupby(['Date'])['Confirmed','Deaths','Recovered','Active'].sum().reset_index()
total.head()
df_prophet=total.rename(columns={'Date':'ds','Confirmed':'y'})
df_prophet.head()
m=Prophet(daily_seasonality=True,yearly_seasonality=True)
model=m.fit(df_prophet)
model.seasonalities
### ### now I am going to do forecasting so to do forecasting I need some Future Days 
future_global=model.make_future_dataframe(periods=30,freq='D')
future_global.head()
df_prophet.shape
future_global.shape
df_prophet['ds'].tail()
future_global.tail()
### now do Prediction on future_global
prediction=model.predict(future_global)
prediction
prediction[['ds','yhat','yhat_lower','yhat_upper']].tail()
#### plot the predictions u will see these are with respect to yhat
model.plot(prediction)<jupyter_output><empty_output><jupyter_text>Conclusion--> This is what our prediction looks like. The direction of overall case numbers is probably true, u will observe how cases rises exponentially<jupyter_code>##### Visualize Each Components[Trends,Weekly]
model.plot_components(prediction)
#### The prophet model identifies points at which the trend changes and those can be plotted.¶
from fbprophet.plot import add_changepoints_to_plot
fig=model.plot(prediction)

a=add_changepoints_to_plot(fig.gca(),model,prediction)
from fbprophet.diagnostics import cross_validation
df_cv=cross_validation(model,horizon='30 days',period='15 days',initial='90 days')
## horizon='365 days'--> for how many days we have to cross validate=====

## Computes forecasts from historical cutoff points Beginning from..

## (end - horizon) it means it is going to take that date that is (end - horizon) bcz on these date we have to just 
## cross-validate for the new dataset that we have to find out

## period=180 as from documentation of func as period=0.5*365=180 or {period=1/2*horizon value}
## initial -How many total no. of days we actually want-- 3*365 from documentation of function or  {initial=3*horizon}
df_cv.head()
df_cv.shape<jupyter_output><empty_output><jupyter_text>Obtaining the Performance Metrics    We use the performance_metrics utility to compute the Mean Squared Error(MSE), Root Mean Squared Error(RMSE),Mean Absolute Error(MAE), Mean Absolute Percentage Error(MAPE) and the coverage of the the yhat_lower and yhat_upper estimates.<jupyter_code>from fbprophet.diagnostics import performance_metrics
df_performance=performance_metrics(df_cv)
df_performance.head()

from fbprophet.plot import plot_cross_validation_metric
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='mape')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11651993785603314, 'fraction_numerical': 0.008544795442775763, 'mean_word_length': 8.829516539440204, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '659285', 'license': 'Apache-2.0', 'n_tokens_mistral': 1299, 'n_tokens_neox': 1222, 'n_words': 293, 'path': 'Covid_Cases_Forecasting_Using_FbProphet.ipynb', 'repo_name': 'Sushma-Niveni/Time-Series-Analysis-of-COvid-19-Cases', 'size': '3862'}