# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import preprocessing
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score

file = r"C:\Users\<NAME>\Desktop\corona virus\covid_19_data.csv"

file

cv19 = pd.read_csv(file)

cv19

parse_dates = cv19["Last Update"]

parse_dates.head()

cv19 = pd.read_csv(file , parse_dates = ["Last Update"])

cv19

cv19.rename(columns={'ObservationDate':'Date', 'Country/Region':'Country'}, inplace=True)

cv19.head()

cv19.isnull().sum()

cv19.shape

cv19.dtypes

cv19.isnull().sum().to_frame("nulls")

dataf = cv19.groupby(["Date", "Country"])[['Date', 'Country', 'Confirmed', 'Deaths', 'Recovered']].sum()

dataf

dataf = cv19.groupby(["Date" , "Country"])[["Date" , "Country" , "Confirmed" , "Deaths" , "Recovered"]].sum().reset_index()

dataf

cv19.groupby(["Country"])[["Deaths"]].sum()

cv19["Country"]

cv19["Country"] == "Mainland China"

cv19.Country.value_counts(normalize=True)

cv19.Confirmed.value_counts()

cv19.Recovered.value_counts()

cv19.groupby(["Country"])[["Recovered"]].sum()

cv19.groupby(["Country"])[["Confirmed"]].sum()

dataf

sorting_By_Confirmed = cv19.sort_values('Confirmed',ascending=False)

sorting_By_Confirmed

sorting_By_Confirmed = sorting_By_Confirmed.drop_duplicates("Country")

sorting_By_Confirmed

Total_Conformed_From_World = sorting_By_Confirmed['Confirmed'].sum()

Total_Conformed_From_World

Total_Deaths_From_world = sorting_By_Confirmed['Deaths'].sum()

Total_Deaths_From_world

Total_Recovered_From_World = sorting_By_Confirmed['Recovered'].sum()

Total_Recovered_From_World

Deaths_rate_Total_World = (Total_Deaths_From_world*100)/Total_Conformed_From_World

Deaths_rate_Total_World

Recovered_rate_Total_World = (Total_Recovered_From_World*100)/Total_Conformed_From_World

Recovered_rate_Total_World

Report_China = sorting_By_Confirmed[sorting_By_Confirmed["Country"] == "Mainland China"]

Report_China

China_Recovered_rate = (int(Report_China["Recovered"].values)*100)/int(Report_China["Confirmed"].values)

China_Recovered_rate

rate_of_recovered = (sorting_By_Confirmed["Recovered"]*100)/sorting_By_Confirmed["Confirmed"]

rate_of_recovered

rate_of_deaths = (sorting_By_Confirmed["Deaths"]*100)/(sorting_By_Confirmed["Confirmed"])

rate_of_deaths

rate_of_cases = (sorting_By_Confirmed["Confirmed"]*100)/Total_Conformed_From_World

rate_of_cases

sorting_By_Confirmed[ " Rate Of Recovered Cases (%) " ] = pd.DataFrame(rate_of_recovered)

sorting_By_Confirmed[ " Rate Of Death Cases (%) " ] = pd.DataFrame(rate_of_deaths)

sorting_By_Confirmed[" Rate Of Total Cases (%) "] = pd.DataFrame(rate_of_cases)

sorting_By_Confirmed

sorting_By_Confirmed.head(100).style.background_gradient(cmap = "Greens")

sorting_By_Confirmed1=sorting_By_Confirmed.head(10)

sorting_By_Confirmed1

x = sorting_By_Confirmed1.Country
y = sorting_By_Confirmed1.Confirmed

x

y

plt.rcParams["figure.figsize"] = (12, 10)
plt.rcParams["figure.edgecolor"] = ("Black")
sns.barplot(x,y  , palette="Blues_d").set_title("Total Number Of Cases / Deaths / Recoverd")

cases_on_per_Day = cv19.groupby(["Date"])['Confirmed','Deaths', 'Recovered'].sum().reset_index()

cases_on_per_Day

sorting_By_Confirmed2 = cases_on_per_Day.sort_values("Date" , ascending=False)

sorting_By_Confirmed2

sorted_By_Confirmed2.style.background_gradient(cmap= "Blues")

x = cases_on_per_Day.index

x

y = cases_on_per_Day.Confirmed

y

y1 = cases_on_per_Day.Deaths

y1

y2 = cases_on_per_Day.Recovered

y2

plt.scatter(x , y , color = "aqua" , label = "CONFORMED CASES")

plt.scatter(x , y1 , color = "tan" ,label = "DEATH CASES")

plt.scatter(x , y2 , color = "lightgrey" , label = "Recover cases")

plt.scatter(x , y , color = "aqua" , label = "CONFORMED CASES")
plt.scatter(x , y1 , color = "tan" ,label = "DEATH CASES")
plt.scatter(x , y2 , color = "lightgrey" , label = "Recover cases")

x_data = pd.DataFrame(cases_on_per_Day.index)

x_data

y_data = pd.DataFrame(cases_on_per_Day.Confirmed)

y_data

from sklearn.model_selection import train_test_split

x_train,x_test,y_train,y_test = train_test_split(x_data,y_data,test_size=0.2,random_state=5)

l_r = LinearRegression()

l_r

l_r.fit(x_train , y_train)

cv19_prediction = l_r.predict(x_test)

cv19_prediction

cv19_prediction_DataFrame = pd.DataFrame(cv19_prediction)

cv19_prediction_DataFrame

cv19_prediction_DataFrame['Predicted Value'] = pd.DataFrame(cv19_prediction)

cv19_prediction_DataFrame

cv19_prediction_DataFrame

from sklearn.metrics import r2_score

print("Linear Regession R2 Score : ", r2_score(y_test, cv19_prediction))

from sklearn.metrics import confusion_matrix, classification_report

from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score
from sklearn.svm import SVC
from sklearn.naive_bayes import MultinomialNB

from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error

cv19_rmse = np.sqrt(mean_squared_error(y_test , cv19_prediction))

cv19_rmse

cv19_rmse1 = mean_squared_error(y_test , cv19_prediction)

cv19_rmse1

cv19_rmse2 = mean_absolute_error(y_test , cv19_prediction)

cv19_rmse2

pd.DataFrame(cv19_prediction).to_csv("cv19_prediction_values.csv",index=False)

















StarcoderdataJupyterScriptsDedupFiltered