<jupyter_start><jupyter_text>India COVID-19 Analysis<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('../datasets/Country_wise_total.csv')
df.head()
India = df[['Unnamed: 0','India_case','India_death','India_recov']]
case = India[['Unnamed: 0', 'India_case']]
case.columns = ['date','case']
case.head()
case[case['case']==1]
df2 = case.iloc[8:,:]
df2.head()
df2.shape
df2['days'] = np.arange(1,105)
from sklearn.preprocessing import PolynomialFeatures
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
p = PolynomialFeatures(degree=5)
X = p.fit_transform(df2[['days']])
y = df2['case']

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2)
lr = LinearRegression()
lr.fit(X_train,y_train)
y_pred = lr.predict(X)
lr.score(X_test,y_test)
lr.score(X_train,y_train), lr.score(X,y)
plt.plot(df2.days,df2.case)
plt.plot(df2.days,y_pred)
df2['lin_pred'] = y_pred
from sklearn.metrics import r2_score
y_exp = [1.115 ** i for i in df2['days']]
r2_score(df2['case'],y_exp)
df2['exp_pred'] = y_exp
plt.plot(df2.days,df2.case)
plt.plot(df2.days,y_exp)
from sklearn.metrics import r2_score
df3 = df2[df2.index%10 == 0]
# df3['date'] = pd.to_datetime(df3['date'])
df3.info()
df3.drop([10,40,50], inplace=True)<jupyter_output>/home/king/anaconda3/lib/python3.7/site-packages/pandas/core/frame.py:4102: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  errors=errors,<jupyter_text><jupyter_code>df3
c = 8.2/2.54
d = 11.8/2.54
df = df3
fig,ax = plt.subplots()
ax.plot(df['date'],df['case'], marker='.')
ax.plot(df['date'], df['lin_pred'], marker='.')
ax.set_xticklabels(df['date'], rotation=90)
plt.legend(['actual','linear regression'])
plt.title('COVID-19 cases in Linear Regression')
fig.set_size_inches(d,c)
plt.savefig('case_vs_linpred.jpg', dpi=300)
fig,ax = plt.subplots()
ax.plot(df['date'],df['case'], marker='.')
ax.plot(df['date'], df['exp_pred'], marker='.')
ax.set_xticklabels(df['date'], rotation=90)
plt.legend(['actual','exponential growth'])
plt.title('COVID-19 cases in exponential growth')
fig.set_size_inches(d,c)
plt.savefig('case_vs_exppred.jpg', dpi=300)
df2['death'] = India['India_death']
df2['recov'] = India['India_recov']
# fig,ax = plt.subplots()
# ax.plot(df['date'],df['death'], marker='.')
# ax.set_xticklabels(df['date'], rotation=90)
# plt.legend(['deaths due to COVID-19'])
# plt.title('COVID-19 deaths')
# fig.set_size_inches(d,c)
# plt.savefig('deaths.jpg', dpi=300)
# fig,ax = plt.subplots()
# ax.plot(df['date'],df['recov'], marker='.')
# ax.set_xticklabels(df['date'], rotation=90)
# plt.legend(['recovers : COVID-19'])
# plt.title('COVID-19 recoveries')
# fig.set_size_inches(d,c)
# plt.savefig('recovery.jpg', dpi=300)
# on may 17

may17 = 109
d = p.transform([[109]])
lr.predict(d)
d = [[111],[118],[125],[132],[139],[146],[153]]
days = ['may 19','may 26','jun 2','jun 9','jun 16', 'jun 23', 'jun 30']
ed = [2,9,16,23,30,37,44]
d2 = p.transform(d)
lr_p = lr.predict(d2)
lr_p
eg = [int(1.115 ** i)*96429 for i in ed]
d = {'Dates':days, 'exp':eg, 'linp':lr_p}
df_p = pd.DataFrame(d)
fig,ax = plt.subplots()
ax.plot(df_p['Dates'],df_p['exp'], marker='.')
ax.plot(df_p['Dates'], df_p['linp'], marker='.')
ax.set_xticklabels(df_p['Dates'], rotation=90)
plt.legend(['exponential growth','Linear growth'])
plt.title('COVID-19 case growth comparision')
plt.yscale('log')
fig.set_size_inches(d,c)
plt.savefig('exp vs lin.jpg', dpi=300)
[round(i,2) for i in lr.coef_]
lr.score(X_train,y_train), lr.score(X_test,y_test)
df
d = pd.Series([99.89, 90.78])
d.index = ['Linear Regression', 'exponential']
d
plt.bar(d.index, d)
l = np.arange(10000).reshape(-1,1)
o = p.transform(l)
d = lr.predict(o)
plt.plot(l,d)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2074949698189135, 'fraction_numerical': 0.04904426559356137, 'mean_word_length': 6.798039215686274, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '381234', 'license': 'Apache-2.0', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1678, 'n_words': 287, 'path': 'notebooks/India Analysis.ipynb', 'repo_name': 'satyalytics/COVID-19', 'size': '3976'}