<jupyter_start><jupyter_text>Data Manipulation Data time Formatting<jupyter_code>coviddf['ObservationDate'] = pd.to_datetime(coviddf['ObservationDate'])
coviddf.head()
covid_datewise = coviddf.groupby(['ObservationDate']).agg({'Confirmed':'sum', 'Deaths':'sum', 'Recovered':'sum'})
covid_datewise.head()
covid_datewise['Active'] = covid_datewise['Confirmed'] - covid_datewise['Deaths'] - covid_datewise['Recovered']
covid_datewise.head()<jupyter_output><empty_output><jupyter_text>iPlot<jupyter_code>covid_datewise.iplot()<jupyter_output><empty_output><jupyter_text>SeaBorn<jupyter_code>sns.set_style('darkgrid') 
plt.figure(figsize=(20,20)) 
sns.barplot(x = covid_datewise.index.date, y = covid_datewise['Confirmed'], palette='YlOrRd') 
plt.xticks(rotation = 90) 
plt.show()<jupyter_output><empty_output><jupyter_text>Mortality Rate<jupyter_code>covid_datewise['Mortality Rate'] = (covid_datewise['Deaths']) / (covid_datewise['Confirmed'] ) * 100<jupyter_output><empty_output><jupyter_text>iPlot<jupyter_code>covid_datewise['Mortality Rate'].iplot()
covid_datewise['Days'] = covid_datewise.index - covid_datewise.index[0]<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code>covid_datewise 
covid_datewise ['Days'] = covid_datewise['Days'].dt.days
covid_datewise
# First 90 % rows for training 
train_ml = covid_datewise.iloc [: int(covid_datewise.shape[0]*.90)]
train_ml
test_ml = covid_datewise.iloc [int(covid_datewise.shape[0]*.90):]
test_ml
test_ml.shape
train_ml.shape<jupyter_output><empty_output><jupyter_text>Linear Regression Algorithm<jupyter_code>from sklearn.linear_model import LinearRegression 
lin_reg = LinearRegression(normalize= True)
X = np.array(train_ml['Days']).reshape(-1,1)
Y = np.array(train_ml['Confirmed']).reshape(-1,1)
print(X)
print(Y)<jupyter_output><empty_output><jupyter_text>Training of Data<jupyter_code>## Predictions
lin_reg.fit(X, Y)
predicted_value = lin_reg.predict(np.array(test_ml['Days']).reshape(-1,1))<jupyter_output><empty_output><jupyter_text>Predictions<jupyter_code>predicted_value = lin_reg.predict(np.array(test_ml['Days']).reshape(-1,1))
predicted_value
predicted_value<jupyter_output><empty_output><jupyter_text>Implement Regression<jupyter_code>predicted_value_all = lin_reg.predict(np.array(covid_datewise['Days']).reshape(-1,1))
plt.figure(figsize=(25,10)) 
plt.plot(covid_datewise['Confirmed'], label = 'Confirmed') 
plt.plot(covid_datewise.index, predicted_value_all, label = 'Predicted Confirmed Cases') 
plt.legend()
plt.show()<jupyter_output><empty_output><jupyter_text>FBProphet: ARIMA                                 ---- Could not complete because could not detect FBProphet ----  RNN Recurrent Neural Network  RNN - LSTM - Times Series Forecasting  Neural Network with Memory  Output will depend upon features (X) and past memory (logic gates that stores part memory)​<jupyter_code># Sequential arrangement of Neural Network
from keras.models import Sequential 
# LSTM - Part of RNN 
from keras.layers import LSTM, Dense 
from keras.layers import Dropout 
from sklearn.preprocessing import MinMaxScaler 
from tensorflow.keras.preprocessing.sequence import TimeseriesGenerator
data = coviddf[coviddf['Country/Region'] == 'India']
data
data = data.loc[:, ['ObservationDate', 'Confirmed']]
data
data = data.groupby('ObservationDate')[['Confirmed']].max().reset_index()
data
dataset = data.drop("ObservationDate", axis = 1)
dataset
data = np.array(dataset).reshape(-1, 1)
train_data = dataset[:len(dataset)-5] 
# For validation take last 5 Values 
test_data = dataset[len(dataset)-5:]
# Data Preprocessing 
# scaling large samples into equal range of (0,1) 
scaler = MinMaxScaler() 
scaler.fit(train_data) 
scaled_train_data = scaler.transform(train_data) 
scaled_test_data = scaler.transform(test_data)
generator = TimeseriesGenerator(scaled_train_data, scaled_train_data, length=n_input, batch_size=10)
## Lstm Model 
lstm_model = Sequential() 
# layer - 1 : Input Layer 
# units = no of neurons , backpropogation: return_sequences, 
lstm_model.add(LSTM(units = 64, return_sequences= True, input_shape = (n_input, n_feature))) 
# Avoid overfitting of model 0.2 = 20% 
lstm_model.add(Dropout(0.2)) 
# Hidden Layer - I
lstm_model.add(LSTM(units = 64, return_sequences= True)) 
lstm_model.add(Dropout(0.2))
# Hidden Layer - II 
lstm_model.add(LSTM(units = 64)) 
lstm_model.add(Dropout(0.2)) 
# Ouput layer 
# In regression : last layer neuron = 1 
lstm_model.add(Dense(units = 1)) 
## Optimization & Loss Function 
lstm_model.compile(optimizer = 'adam', loss='mean_squared_error')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13346396690616155, 'fraction_numerical': 0.013281079904202046, 'mean_word_length': 7.783938814531549, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '217622', 'license': 'MIT', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1664, 'n_words': 270, 'path': '170520AIworkshop06 COVID19 Forecasting.ipynb', 'repo_name': 'tanujp99/Novel-COVID19-Analysis', 'size': '4593'}