Shrikrishna commited on
Commit
3f61e0e
1 Parent(s): 5174f1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py CHANGED
@@ -45,3 +45,47 @@ st.pyplot(fig)
45
  data_training = pd.DataFrame(df["Close"][0:int(len(df)*0.70)])
46
  data_testing = pd.DataFrame(df["Close"][int(len(df)*0.70):int(len(df))])
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  data_training = pd.DataFrame(df["Close"][0:int(len(df)*0.70)])
46
  data_testing = pd.DataFrame(df["Close"][int(len(df)*0.70):int(len(df))])
47
 
48
+ #Scaling
49
+ scaler = MinMaxScaler(feature_range=(0,1))
50
+ data_training_arr = scaler.fit_transform(data_training)
51
+
52
+ #Split data in x_train and y_train
53
+ x_train = []
54
+ y_train = []
55
+ for i in range(100, data_training_arr.shape[0]):
56
+ x_train.append(data_training_arr[i-100: i])
57
+ y_train.append(data_training_arr[i, 0])
58
+ x_train, y_train = np.array(x_train), np.array(y_train)
59
+
60
+ #Load the model
61
+ model = load_model("keras_model.h5")
62
+
63
+ past_100_days = data_training.tail(100)
64
+ final_test_df = past_100_days._append(data_testing, ignore_index=True)
65
+ input_data = scaler.fit_transform(final_test_df)
66
+
67
+ #Split data in x_test and y_test
68
+ x_test = []
69
+ y_test = []
70
+
71
+ for i in range(100, input_data.shape[0]):
72
+ x_test.append(input_data[i-100: i])
73
+ y_test.append(input_data[i, 0])
74
+
75
+ x_test, y_test = np.array(x_test), np.array(y_test)
76
+
77
+ y_predicted = model.predict(x_test)
78
+
79
+ sc = scaler.scale_
80
+ scale_factor = 1/sc[0]
81
+
82
+ y_predicted = y_predicted * scale_factor
83
+ y_test = y_test * scale_factor
84
+
85
+ plt.figure(figsize=(12,6))
86
+ plt.plot(y_test, 'blue', label="Original Stock Price")
87
+ plt.plot(y_predicted, 'red', label="Predicted Stock Price")
88
+ plt.xlabel('Time')
89
+ plt.ylabel('Price')
90
+ plt.legend()
91
+ plt.show()