Spaces:
Running
Running
Gil Stetler
commited on
Commit
·
0262268
1
Parent(s):
3c3c589
fix train autogluon
Browse files- train_autogluon.py +31 -11
train_autogluon.py
CHANGED
|
@@ -1,39 +1,59 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
from utils_vol import fetch_close_series, realized_vol, rv_to_autogluon_df
|
| 3 |
|
| 4 |
-
def train_bolt_small(
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"""
|
| 7 |
-
|
| 8 |
-
|
| 9 |
"""
|
| 10 |
-
print(f"[AutoFT] Lade {ticker}...")
|
| 11 |
close = fetch_close_series(ticker, start=start, interval=interval)
|
| 12 |
rv = realized_vol(close)
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
predictor = TimeSeriesPredictor(
|
| 16 |
path="/mnt/data/AutogluonChronosBoltSmall",
|
| 17 |
prediction_length=prediction_length,
|
| 18 |
eval_metric="WQL",
|
|
|
|
| 19 |
verbosity=2,
|
| 20 |
)
|
| 21 |
|
| 22 |
predictor.fit(
|
| 23 |
-
train_data=
|
| 24 |
enable_ensemble=False,
|
| 25 |
num_val_windows=1,
|
| 26 |
hyperparameters={
|
| 27 |
"Chronos": {
|
| 28 |
"model_path": "autogluon/chronos-bolt-small",
|
| 29 |
"fine_tune": True,
|
| 30 |
-
"fine_tune_steps": 200,
|
| 31 |
"fine_tune_lr": 1e-4,
|
| 32 |
-
"context_length": 128,
|
| 33 |
"quantile_levels": [0.1, 0.5, 0.9],
|
| 34 |
}
|
| 35 |
},
|
| 36 |
-
time_limit=time_limit,
|
| 37 |
)
|
| 38 |
|
| 39 |
print("✅ Training abgeschlossen. Modellpfad:", predictor.path)
|
|
|
|
| 1 |
+
# train_autogluon.py
|
| 2 |
+
from autogluon.timeseries import TimeSeriesPredictor, TimeSeriesDataFrame
|
| 3 |
from utils_vol import fetch_close_series, realized_vol, rv_to_autogluon_df
|
| 4 |
|
| 5 |
+
def train_bolt_small(
|
| 6 |
+
ticker="AAPL",
|
| 7 |
+
start="2015-01-01",
|
| 8 |
+
interval="1d",
|
| 9 |
+
prediction_length=30,
|
| 10 |
+
time_limit=900, # seconds (15 min). Adjust if needed.
|
| 11 |
+
):
|
| 12 |
"""
|
| 13 |
+
Trains Chronos-Bolt-Small on CPU via AutoGluon with strict CPU-friendly limits.
|
| 14 |
+
Uses business-day ('B') frequency to handle weekends/holidays.
|
| 15 |
"""
|
| 16 |
+
print(f"[AutoFT] Lade {ticker} ...")
|
| 17 |
close = fetch_close_series(ticker, start=start, interval=interval)
|
| 18 |
rv = realized_vol(close)
|
| 19 |
+
|
| 20 |
+
# Make a tidy dataframe
|
| 21 |
+
df = rv_to_autogluon_df(rv) # columns: item_id, timestamp, target
|
| 22 |
+
|
| 23 |
+
# Create a TimeSeriesDataFrame with explicit frequency
|
| 24 |
+
tsdf = TimeSeriesDataFrame.from_data_frame(
|
| 25 |
+
df,
|
| 26 |
+
id_column="item_id",
|
| 27 |
+
timestamp_column="timestamp",
|
| 28 |
+
target_column="target",
|
| 29 |
+
freq="B", # <- set business-day freq
|
| 30 |
+
)
|
| 31 |
+
# Ensure regular frequency (fills gaps with NaNs)
|
| 32 |
+
tsdf = tsdf.convert_frequency("B")
|
| 33 |
|
| 34 |
predictor = TimeSeriesPredictor(
|
| 35 |
path="/mnt/data/AutogluonChronosBoltSmall",
|
| 36 |
prediction_length=prediction_length,
|
| 37 |
eval_metric="WQL",
|
| 38 |
+
freq="B", # <- set freq on predictor too
|
| 39 |
verbosity=2,
|
| 40 |
)
|
| 41 |
|
| 42 |
predictor.fit(
|
| 43 |
+
train_data=tsdf,
|
| 44 |
enable_ensemble=False,
|
| 45 |
num_val_windows=1,
|
| 46 |
hyperparameters={
|
| 47 |
"Chronos": {
|
| 48 |
"model_path": "autogluon/chronos-bolt-small",
|
| 49 |
"fine_tune": True,
|
| 50 |
+
"fine_tune_steps": 200, # keep small for CPU
|
| 51 |
"fine_tune_lr": 1e-4,
|
| 52 |
+
"context_length": 128, # keep small for CPU
|
| 53 |
"quantile_levels": [0.1, 0.5, 0.9],
|
| 54 |
}
|
| 55 |
},
|
| 56 |
+
time_limit=time_limit, # hard cap so HF Space won’t time out
|
| 57 |
)
|
| 58 |
|
| 59 |
print("✅ Training abgeschlossen. Modellpfad:", predictor.path)
|