forked from ayeshafalak/covidcases_prediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvr_covid.py
127 lines (74 loc) · 1.9 KB
/
svr_covid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env python
# coding: utf-8
# Importing Modules:
import streamlit as st
import pandas as pd
import numpy as np
import datetime as dt
from datetime import datetime,date,time
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVR
# Taking Input Date From User:
st.write("Covid-19 Cases Prediction for UPCOMING WEEK")
predictdate= st.date_input('Input Date')
predictdate=pd.to_datetime(predictdate)
predictdate=predictdate.toordinal()
# Reading Dataset:
df=pd.read_csv('covid-data.csv')
# EDA:
df.info()
df.tail()
df.describe()
# Preprocessing:
df['Confirmed']=df['TT']
df.reset_index(drop=True, inplace=True)
df.sum(axis=0)
df.Confirmed.mean()
df=df[df.Status=='Confirmed']
df=df.drop(columns='Status', axis=1)
columns=['Date', 'Confirmed']
df=df[columns]
df.head()
df.groupby('Date').mean()
df['Date']=pd.to_datetime(df['Date'])
df['Date']=df['Date'].map(dt.datetime.toordinal)
# Model :
x=df['Date']
y=df['Confirmed']
x.reset_index(drop=True, inplace=True)
y.reset_index(drop=True, inplace=True)
l=len(x)
x[l]=predictdate
x=np.array(x).reshape(-1,1)
y=np.array(y).reshape(-1,1)
# Scaling:
sc=StandardScaler()
fX=sc.fit_transform(x)
fY=sc.fit_transform(y)
# training:
ans=fX[len(fX)-1][0]
fX=fX[:len(fX)-1]
model=SVR(kernel='rbf')
model.fit(fX,fY.ravel())
# Prediction:
pred=model.predict(fX)
pred=sc.inverse_transform(pred)
pred=np.array(pred).reshape(-1,1)
# Accuracy:
score=model.score(fX,fY)*100
#Predicting new data
ans=model.predict(np.array(ans).reshape(-1,1))
ans=sc.inverse_transform(ans)
st.write("Predicted cases ")
result=int(ans[0])
result
# Data Visualization:
fdf=pd.DataFrame(pred)
fdf.plot()
df.plot.scatter(x='Date',y='Confirmed')
st.write("Confirmed Cases")
st.line_chart(y)
st.write("Prediction Graph")
st.line_chart(fdf)
st.write("Made by Ayesha Falak using Supervised Machine Learning ")