Add FastAPI backend for energy trading system
Implements FastAPI backend with ML model support for energy trading, including price prediction models and RL-based battery trading policy. Features dashboard, trading, backtest, and settings API routes with WebSocket support for real-time updates.
This commit is contained in:
25
backend/app/ml/utils/data_split.py
Normal file
25
backend/app/ml/utils/data_split.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from typing import Tuple
|
||||
import pandas as pd
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def time_based_split(
|
||||
df: pd.DataFrame,
|
||||
timestamp_col: str = "timestamp",
|
||||
train_pct: float = 0.70,
|
||||
val_pct: float = 0.85,
|
||||
) -> Tuple[pd.DataFrame, pd.DataFrame, pd.DataFrame]:
|
||||
df_sorted = df.sort_values(timestamp_col)
|
||||
|
||||
n_total = len(df_sorted)
|
||||
n_train = int(n_total * train_pct)
|
||||
n_val = int(n_total * val_pct)
|
||||
|
||||
train = df_sorted.iloc[:n_train]
|
||||
val = df_sorted.iloc[n_train:n_val]
|
||||
test = df_sorted.iloc[n_val:]
|
||||
|
||||
return train, val, test
|
||||
|
||||
|
||||
__all__ = ["time_based_split"]
|
||||
Reference in New Issue
Block a user