Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ def download_data(ticker, start_date='2010-01-01'):
|
|
15 |
if 'Adj Close' in data.columns:
|
16 |
data = data[['Date', 'Adj Close']].copy()
|
17 |
data.rename(columns={'Date': 'ds', 'Adj Close': 'y'}, inplace=True)
|
|
|
18 |
else:
|
19 |
raise ValueError("Expected 'Adj Close' in columns")
|
20 |
return data
|
@@ -31,19 +32,18 @@ def predict_future_prices(ticker, periods=1825):
|
|
31 |
forecast = model.predict(future)
|
32 |
|
33 |
# ์์ธก ๊ฒฐ๊ณผ ๊ทธ๋ํ ์์ฑ
|
34 |
-
forecast['ds'] = pd.to_datetime(forecast['ds']) # Ensure 'ds' is datetime type
|
35 |
fig_main = go.Figure()
|
36 |
-
fig_main.add_trace(go.Scatter(x=forecast['ds'], y=forecast['yhat'], mode='lines', name='Forecast (Blue)'))
|
37 |
fig_main.add_trace(go.Scatter(x=data['ds'], y=data['y'], mode='lines', name='Actual (Black)', line=dict(color='black')))
|
|
|
38 |
|
39 |
# ์ฐ๊ฐ ๋ฐ ์ฃผ๊ฐ ๊ณ์ ์ฑ ๊ทธ๋ํ ์์ฑ
|
40 |
-
|
41 |
fig_seasonal = model.plot_components(forecast)
|
42 |
-
forecast['ds'] = pd.to_datetime(forecast['ds']) # Revert to datetime type
|
43 |
-
|
44 |
-
fig_yearly = px.line(x=pd.to_datetime(fig_seasonal[0]['ds']), y=fig_seasonal[0]['yearly'], labels={'x': 'Date', 'y': 'Yearly Trend'})
|
45 |
-
fig_weekly = px.line(x=fig_seasonal[1]['day'], y=fig_seasonal[1]['weekly'], labels={'x': 'Day of Week', 'y': 'Weekly Trend'})
|
46 |
|
|
|
|
|
|
|
47 |
return fig_main, forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']], fig_yearly, fig_weekly
|
48 |
|
49 |
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ฐ ์คํ
|
|
|
15 |
if 'Adj Close' in data.columns:
|
16 |
data = data[['Date', 'Adj Close']].copy()
|
17 |
data.rename(columns={'Date': 'ds', 'Adj Close': 'y'}, inplace=True)
|
18 |
+
data['ds'] = pd.to_datetime(data['ds']) # Ensure 'ds' is datetime type
|
19 |
else:
|
20 |
raise ValueError("Expected 'Adj Close' in columns")
|
21 |
return data
|
|
|
32 |
forecast = model.predict(future)
|
33 |
|
34 |
# ์์ธก ๊ฒฐ๊ณผ ๊ทธ๋ํ ์์ฑ
|
|
|
35 |
fig_main = go.Figure()
|
|
|
36 |
fig_main.add_trace(go.Scatter(x=data['ds'], y=data['y'], mode='lines', name='Actual (Black)', line=dict(color='black')))
|
37 |
+
fig_main.add_trace(go.Scatter(x=forecast['ds'], y=forecast['yhat'], mode='lines', name='Forecast (Blue)'))
|
38 |
|
39 |
# ์ฐ๊ฐ ๋ฐ ์ฃผ๊ฐ ๊ณ์ ์ฑ ๊ทธ๋ํ ์์ฑ
|
40 |
+
# ์์๋ก matplotlib ํ๋กฏ ๋ฐํ์ ๋นํ์ฑํํ๊ณ ๊ฒฐ๊ณผ๋ง ๋ฐํ
|
41 |
fig_seasonal = model.plot_components(forecast)
|
42 |
+
forecast['ds'] = pd.to_datetime(forecast['ds']) # Revert to datetime type to avoid AttributeError
|
|
|
|
|
|
|
43 |
|
44 |
+
fig_yearly = px.line(x=pd.to_datetime(forecast['ds']), y=forecast['yearly'], labels={'x': 'Date', 'y': 'Yearly Trend'})
|
45 |
+
fig_weekly = px.line(x=pd.to_datetime(forecast['ds']), y=forecast['weekly'], labels={'x': 'Date', 'y': 'Weekly Trend'})
|
46 |
+
|
47 |
return fig_main, forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']], fig_yearly, fig_weekly
|
48 |
|
49 |
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ฐ ์คํ
|