TuanScientist commited on
Commit
fc9d5c1
1 Parent(s): 0b0d2de

Upload gardio_forecast.py

Browse files
Files changed (1) hide show
  1. gardio_forecast.py +54 -0
gardio_forecast.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from neuralprophet import NeuralProphet, set_log_level
4
+ import io
5
+ import warnings
6
+
7
+ warnings.filterwarnings("ignore", category=UserWarning)
8
+
9
+ set_log_level("ERROR")
10
+
11
+ url = "VN Index Historical Data.csv"
12
+ df = pd.read_csv(url)
13
+ df = df[["Date", "Price"]]
14
+ df = df.rename(columns={"Date": "ds", "Price": "y"})
15
+ df.fillna(method='ffill', inplace=True)
16
+ df.dropna(inplace=True)
17
+
18
+ m = NeuralProphet(
19
+ n_forecasts=30,
20
+ n_lags=12,
21
+ changepoints_range=5,
22
+ num_hidden_layers=6,
23
+ yearly_seasonality=True,
24
+ n_changepoints=150,
25
+ trend_reg_threshold=False, # Disable trend regularization threshold
26
+ d_hidden=9,
27
+ global_normalization=True,
28
+ seasonality_reg=1,
29
+ unknown_data_normalization=True,
30
+ seasonality_mode="multiplicative",
31
+ drop_missing=True,
32
+ learning_rate=0.1
33
+ )
34
+
35
+ m.fit(df, freq='D')
36
+
37
+ future = m.make_future_dataframe(df, periods=30, n_historic_predictions=True)
38
+ forecast = m.predict(future)
39
+
40
+
41
+ def predict_vn_index(option=None):
42
+ fig = m.plot(forecast)
43
+ path = "forecast_plot.png"
44
+ fig.savefig(path)
45
+ return path
46
+
47
+
48
+ if __name__ == "__main__":
49
+ dropdown = gr.inputs.Dropdown(["VNIndex"], label="Choose an option", default="VNIndex")
50
+ interface = gr.Interface(fn=predict_vn_index, inputs=dropdown, outputs="image", title="Dự báo VN Index 30 ngày tới")
51
+ interface.launch(share=True)
52
+
53
+
54
+