kingabzpro commited on
Commit
facab2e
1 Parent(s): 074b78e

Sync App files

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -130,6 +130,11 @@ class StockPredictor:
130
  # Define features
131
  features = ["year", "month", "day", "ma_5", "ma_10"]
132
 
 
 
 
 
 
133
  # Use the last available values for features
134
  last_date = data["date"].max()
135
  next_30_days = pd.date_range(
@@ -165,22 +170,16 @@ class StockPredictor:
165
  {"date": next_30_days, "predicted_close": predictions}
166
  )
167
 
168
- # Concatenate actual and predicted data for plotting
169
- actual_df = data[["date", "close"]].iloc[-30:].copy()
170
- actual_df.rename(columns={"close": "actual_close"}, inplace=True)
171
- plot_data = pd.concat([actual_df, prediction_df], ignore_index=True)
 
 
172
 
173
  plt.figure(figsize=(14, 7))
174
- plt.plot(
175
- plot_data["date"].iloc[:30],
176
- plot_data["actual_close"].iloc[:30],
177
- label="Actual",
178
- )
179
- plt.plot(
180
- plot_data["date"].iloc[30:],
181
- plot_data["predicted_close"].iloc[30:],
182
- label="Predicted",
183
- )
184
  plt.xlabel("Date")
185
  plt.ylabel("Stock Price")
186
  plt.title(
@@ -229,7 +228,7 @@ def create_gradio_interface(stock_predictor):
229
  fn=stock_predictor.forecast,
230
  inputs=[dropdown, slider],
231
  outputs=[
232
- gr.DataFrame(headers=["date", "actual_close", "predicted_close"]),
233
  gr.Image(type="numpy"),
234
  ],
235
  title="Stock Price Forecasting",
 
130
  # Define features
131
  features = ["year", "month", "day", "ma_5", "ma_10"]
132
 
133
+ # Predict the actual values in the dataset
134
+ X_actual = data[features]
135
+ actual_predictions = model.predict(X_actual)
136
+ data["predicted_close"] = actual_predictions
137
+
138
  # Use the last available values for features
139
  last_date = data["date"].max()
140
  next_30_days = pd.date_range(
 
170
  {"date": next_30_days, "predicted_close": predictions}
171
  )
172
 
173
+ # Concatenate actual and predicted data for plotting, limiting to last 60 days
174
+ combined_df = pd.concat(
175
+ [data[["date", "close", "predicted_close"]], prediction_df],
176
+ ignore_index=True,
177
+ )
178
+ plot_data = combined_df.tail(60)
179
 
180
  plt.figure(figsize=(14, 7))
181
+ plt.plot(plot_data["date"], plot_data["close"], label="Actual")
182
+ plt.plot(plot_data["date"], plot_data["predicted_close"], label="Predicted")
 
 
 
 
 
 
 
 
183
  plt.xlabel("Date")
184
  plt.ylabel("Stock Price")
185
  plt.title(
 
228
  fn=stock_predictor.forecast,
229
  inputs=[dropdown, slider],
230
  outputs=[
231
+ gr.DataFrame(headers=["date", "close", "predicted_close"]),
232
  gr.Image(type="numpy"),
233
  ],
234
  title="Stock Price Forecasting",