MYTHOSLIVE / models /base_model.py
3VVM's picture
Upload folder using huggingface_hub
8bf6b71 verified
Raw History Blame Contribute Delete
750 Bytes
import numpy as np
import pandas as pd
from abc import ABC, abstractmethod
def validate_history_and_horizon(history, horizon: int, model_name: str) -> None:
if horizon < 1:
raise ValueError(f'{model_name}: horizon must be >= 1, got {horizon}.')
values = np.asarray(pd.Series(history).astype(float), dtype=float)
if not np.all(np.isfinite(values)):
raise ValueError(f'{model_name}: price history contains NaN/inf. This usually means a data glitch left a missing or malformed candle -- re-fetch the history and try again.')
class BaseForecastModel(ABC):
name = 'base'
@abstractmethod
def predict(self, history: pd.Series, horizon: int=1, features: pd.DataFrame=None) -> list:
raise NotImplementedError