nalinrajendran commited on
Commit
f001b09
·
1 Parent(s): 69b6e69

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -116
app.py DELETED
@@ -1,116 +0,0 @@
1
-
2
- import pandas as pd
3
- import math
4
- import matplotlib.pyplot as plt
5
- import numpy as np
6
- import os
7
- import seaborn as sns
8
- import keras
9
- import tensorflow as tf
10
- from sklearn.preprocessing import MinMaxScaler
11
- from tensorflow.keras.models import Sequential
12
- from tensorflow.keras.layers import Dense
13
- from tensorflow.keras.layers import LSTM
14
- from sklearn.metrics import mean_squared_error
15
- from sklearn.metrics import mean_absolute_error as MAE
16
-
17
-
18
- pwd = os.getcwd()
19
- filepath = os.path.join(pwd,r"DATA/try_data.csv")
20
-
21
- df = pd.read_csv(filepath)
22
-
23
- df1 = df.reset_index()['cases']
24
-
25
- scaler = MinMaxScaler(feature_range=(0,1))
26
- df1 = scaler.fit_transform(np.array(df1).reshape(-1,1))
27
-
28
- training_size = int(len(df1)*0.8)
29
- test_size= len(df1)-training_size
30
-
31
- train_data,test_data = df1[0:training_size,:],df1[training_size:len(df1),:1]
32
-
33
- def create_dataset (dataset,time_step=1):
34
- dataX, dataY = [], []
35
- for i in range(len(dataset)-time_step-1):
36
- a = dataset[i:(i+time_step),0]
37
- dataX.append(a)
38
- dataY.append(dataset[i+time_step, 0])
39
- return np.array(dataX), np.array(dataY)
40
-
41
-
42
- time_step = 2
43
- X_train, y_train = create_dataset(train_data, time_step)
44
- X_test, y_test = create_dataset(test_data, time_step)
45
-
46
-
47
- X_train = X_train.reshape(X_train.shape[0], X_train.shape[1], 1)
48
- X_test = X_test.reshape(X_test.shape[0], X_test.shape[1], 1)
49
-
50
-
51
- model = Sequential()
52
- model.add(LSTM(11,return_sequences=True, input_shape=(2,1)))
53
- model.add(LSTM(11,return_sequences=True))
54
- model.add(LSTM(11))
55
- model.add(Dense(1))
56
- model.compile(loss='mean_squared_error', optimizer = "adam")
57
-
58
- lin_model=model.fit(X_train, y_train, validation_data=(X_test,y_test), epochs=400, batch_size=38, verbose=1)
59
-
60
- train_predict=model.predict(X_train)
61
- test_predict=model.predict(X_test)
62
-
63
-
64
-
65
- look_back=2
66
- trainPredictPlot = np.empty_like(df1)
67
- trainPredictPlot[:, :] = np.nan
68
- trainPredictPlot[look_back:len(train_predict)+look_back, :] = train_predict
69
-
70
-
71
- # shift test predictions for plotting
72
- testPredictPlot = np.empty_like(df1)
73
- testPredictPlot[:, :] = np.nan
74
- testPredictPlot[len(train_predict)+(look_back*2)+1:len(df1)-1, :] = test_predict
75
-
76
-
77
- # plot baseline and predictions
78
- plt.figure(figsize = (15,6))
79
- plt.plot(scaler.inverse_transform(df1),'r',label='Original Data')
80
- plt.plot(trainPredictPlot,'g',label='Train Data')
81
- plt.plot(testPredictPlot,'b',label='Test Data')
82
- plt.xlabel('Months')
83
- plt.ylabel('Cases')
84
- plt.show()
85
-
86
-
87
-
88
- import gradio as gr
89
- import pandas as pd
90
- import seaborn as sns
91
- import matplotlib.pyplot as plt
92
-
93
- def plot(df):
94
-
95
-
96
- plt.plot(scaler.inverse_transform(df1),'r',label='Original Data')
97
- plt.title("Original data that is used for analysis")
98
- plt.savefig("original_data.png")
99
- plt.plot(trainPredictPlot,'g',label='Train Data')
100
- plt.title("Predicting the Trained data from the original data")
101
- plt.savefig("train_prediction.png")
102
- plt.plot(testPredictPlot,'b',label='Test Data')
103
- plt.title("Predicting the case coutn of the year 2020 and 2021")
104
- plt.savefig("test_prediction.png")
105
-
106
-
107
- plots = ["Case_count.png","Rainfall_pattern.png","original_data.png","train_prediction.png", "test_prediction.png"]
108
- return plots
109
-
110
- inputs = [gr.Dataframe(label="Dengue Data")]
111
- outputs = [gr.Gallery(label="Inference from the data").style(grid=(5,1))]
112
- description = "We are given with the dataset of dengue cases with respect to the state Kerala with a span ranging from the year 2011 to 2021.The goal is to predict the cases in a monthly fashion, for the upcoming years.The bar graph indicated the year-wise dengue case count.The Time series plot indicates the rainfall pattern across the period 2011-2021.The red part of the graph is the input data that we have .The green part of the graph is the data with which we trained our model.The blue part of the graph indicates the predicted output(test data) against the red part which is the original data"
113
-
114
- gr.Interface(plot, inputs=inputs, outputs=outputs, title="Dengue Cases Prediction Dashboard",description=description,allow_flagging="never").launch()
115
-
116
-