Coronavirus prediction with python and ML
IMPORTS
import pandas as pd
import plotly.express as px
import math
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
import plotly.graph_objects as go
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, Dropout
from tensorflow.keras.callbacks import ModelCheckpoint, TensorBoard
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from collections import deque
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import random
import time
import os
The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
We recommend you upgrade now
or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x
magic:
more info.
LOAD dataset
from google.colab import drive
drive.mount('/content/drive')
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).
virusdata = "/content/drive/My Drive/data/2019_nCoV_data.csv"
virus_data = pd.read_csv(virusdata)
virus_data
Sno | Date | Province/State | Country | Last Update | Confirmed | Deaths | Recovered | |
---|---|---|---|---|---|---|---|---|
0 | 1 | 01/22/2020 12:00:00 | Anhui | China | 2020-01-22 12:00:00 | 1.0 | 0.0 | 0.0 |
1 | 2 | 01/22/2020 12:00:00 | Beijing | China | 2020-01-22 12:00:00 | 14.0 | 0.0 | 0.0 |
2 | 3 | 01/22/2020 12:00:00 | Chongqing | China | 2020-01-22 12:00:00 | 6.0 | 0.0 | 0.0 |
3 | 4 | 01/22/2020 12:00:00 | Fujian | China | 2020-01-22 12:00:00 | 1.0 | 0.0 | 0.0 |
4 | 5 | 01/22/2020 12:00:00 | Gansu | China | 2020-01-22 12:00:00 | 0.0 | 0.0 | 0.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
695 | 696 | 02/03/2020 21:40:00 | Boston, MA | US | 2020-01-02 19:43:00 | 1.0 | 0.0 | 0.0 |
696 | 697 | 02/03/2020 21:40:00 | Los Angeles, CA | US | 2020-01-02 19:53:00 | 1.0 | 0.0 | 0.0 |
697 | 698 | 02/03/2020 21:40:00 | Orange, CA | US | 2020-01-02 19:53:00 | 1.0 | 0.0 | 0.0 |
698 | 699 | 02/03/2020 21:40:00 | Seattle, WA | US | 2020-01-02 19:43:00 | 1.0 | 0.0 | 0.0 |
699 | 700 | 02/03/2020 21:40:00 | Tempe, AZ | US | 2020-01-02 19:43:00 | 1.0 | 0.0 | 0.0 |
700 rows × 8 columns
</div>
SUM ALL
Confirmed infections
import plotly.graph_objects as go
grouped_multiple = virus_data.groupby(['Date']).agg({'Confirmed': ['sum']})
grouped_multiple.columns = ['Confirmed ALL']
grouped_multiple = grouped_multiple.reset_index()
fig = go.Figure()
fig.update_layout(template='plotly_dark')
fig.add_trace(go.Scatter(x=grouped_multiple['Date'],
y=grouped_multiple['Confirmed ALL'],
mode='lines+markers',
name='Deaths',
line=dict(color='orange', width=2)))
fig.show()