Spaces:
Sleeping
Sleeping
Update core/model_runner.py
Browse files- core/model_runner.py +30 -7
core/model_runner.py
CHANGED
|
@@ -1,13 +1,36 @@
|
|
| 1 |
-
|
| 2 |
-
from .train_eval import train_and_evaluate
|
|
|
|
| 3 |
|
| 4 |
-
def get_model(df, model_name, horizon,
|
| 5 |
-
|
| 6 |
"LSTM": LSTMModel,
|
| 7 |
"GRU": GRUModel,
|
| 8 |
-
"BiLSTM": BiLSTMModel,
|
| 9 |
"CNN": CNNModel,
|
| 10 |
"Transformer": TransformerModel,
|
|
|
|
|
|
|
| 11 |
"Hybrid": HybridModel
|
| 12 |
-
}
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from core.train_eval import train_and_evaluate
|
| 3 |
+
from core.models import LSTMModel, GRUModel, CNNModel, TransformerModel, MLPModel, BiLSTMModel, HybridModel
|
| 4 |
|
| 5 |
+
def get_model(df, model_name, horizon, hidden_units, n_layers, epochs, learning_rate, beta1, beta2, weight_decay, dropout, window_size, test_split):
|
| 6 |
+
model_map = {
|
| 7 |
"LSTM": LSTMModel,
|
| 8 |
"GRU": GRUModel,
|
|
|
|
| 9 |
"CNN": CNNModel,
|
| 10 |
"Transformer": TransformerModel,
|
| 11 |
+
"MLP": MLPModel,
|
| 12 |
+
"BiLSTM": BiLSTMModel,
|
| 13 |
"Hybrid": HybridModel
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
if model_name not in model_map:
|
| 17 |
+
raise ValueError(f"Model {model_name} not supported.")
|
| 18 |
+
|
| 19 |
+
model_cls = model_map[model_name]
|
| 20 |
+
result = train_and_evaluate(
|
| 21 |
+
df=df,
|
| 22 |
+
model_cls=model_cls,
|
| 23 |
+
horizon=horizon,
|
| 24 |
+
hidden=hidden_units,
|
| 25 |
+
layers=n_layers,
|
| 26 |
+
epochs=epochs,
|
| 27 |
+
lr=learning_rate,
|
| 28 |
+
beta1=beta1,
|
| 29 |
+
beta2=beta2,
|
| 30 |
+
weight_decay=weight_decay,
|
| 31 |
+
dropout=dropout,
|
| 32 |
+
window=window_size,
|
| 33 |
+
test_split=test_split
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
return result
|