mirror of
https://github.com/webclinic017/drift.git
synced 2026-07-27 18:57:55 +00:00
feat(Config): added start_date property (#245)
* refactor(Training): remove non-expanding window option * feat(Config): added `start_date` property * fix(Inference): added start_date here as well * fix(Linter): ran
This commit is contained in:
committed by
GitHub
parent
0395715fa1
commit
5482e3fc95
@@ -20,6 +20,7 @@ def hash_data_config(data_config: dict) -> str:
|
||||
data_config["target_asset"].path
|
||||
+ data_config["target_asset"].file_name,
|
||||
data_config["load_non_target_asset"],
|
||||
data_config["start_date"],
|
||||
hash_feature_extractors(data_config["own_features"]),
|
||||
hash_feature_extractors(data_config["other_features"]),
|
||||
hash_feature_extractors(data_config["exogenous_features"]),
|
||||
|
||||
@@ -14,6 +14,7 @@ def get_default_config() -> RawConfig:
|
||||
meta_models = ["LogisticRegression_two_class", "LGBM"]
|
||||
|
||||
return RawConfig(
|
||||
start_date=None,
|
||||
dimensionality_reduction_ratio=0.5,
|
||||
n_features_to_select=50,
|
||||
initial_window_size=3800,
|
||||
|
||||
+2
-1
@@ -11,6 +11,7 @@ from transformations.base import Transformation
|
||||
|
||||
# RawConfig is needed to ensure we can declare config presets here with static typing, we then convert it to Config
|
||||
class RawConfig(BaseModel):
|
||||
start_date: Optional[str]
|
||||
dimensionality_reduction_ratio: float
|
||||
n_features_to_select: int
|
||||
initial_window_size: int
|
||||
@@ -40,9 +41,9 @@ class RawConfig(BaseModel):
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
start_date: Optional[str]
|
||||
initial_window_size: int
|
||||
retrain_every: int
|
||||
|
||||
assets: DataCollection
|
||||
target_asset: DataSource
|
||||
other_assets: DataCollection
|
||||
|
||||
@@ -33,6 +33,7 @@ def __load_data(
|
||||
own_features: list[tuple[str, FeatureExtractor, list[int]]],
|
||||
other_features: list[tuple[str, FeatureExtractor, list[int]]],
|
||||
exogenous_features: list[tuple[str, FeatureExtractor, list[int]]],
|
||||
start_date: Optional[str],
|
||||
) -> tuple[XDataFrame, ReturnSeries]:
|
||||
"""
|
||||
Loads asset data from the specified path.
|
||||
@@ -98,6 +99,9 @@ def __load_data(
|
||||
X = pd.concat([df.reindex(X[0].index) for df in X], axis=1).fillna(0.0)
|
||||
|
||||
X.index = pd.DatetimeIndex(X.index)
|
||||
if start_date is not None:
|
||||
X = X[start_date:]
|
||||
df_target_asset_only_returns = df_target_asset_only_returns[start_date:]
|
||||
|
||||
## Create target
|
||||
returns = df_target_asset_only_returns[target_asset.file_name + "_returns"]
|
||||
|
||||
@@ -18,4 +18,4 @@ def check_data(X: XDataFrame, config: Config) -> bool:
|
||||
def has_enough_samples_to_train(X: XDataFrame, config: Config) -> bool:
|
||||
first_valid_index = get_first_valid_return_index(X.iloc[:, 0])
|
||||
samples_to_train = len(X) - first_valid_index
|
||||
return samples_to_train > (config.initial_window_size * 2) + 100
|
||||
return samples_to_train > config.retrain_every * 3 + config.initial_window_size
|
||||
|
||||
@@ -39,6 +39,7 @@ def __inference(config: Config, pipeline_outcome: PipelineOutcome):
|
||||
own_features=config.own_features,
|
||||
other_features=config.other_features,
|
||||
exogenous_features=config.exogenous_features,
|
||||
start_date=config.start_date,
|
||||
)
|
||||
assert check_data(X, config) == True, "Data is not valid. Cancelling Inference."
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ def run_training(config: Config) -> PipelineOutcome:
|
||||
own_features=config.own_features,
|
||||
other_features=config.other_features,
|
||||
exogenous_features=config.exogenous_features,
|
||||
start_date=config.start_date,
|
||||
)
|
||||
|
||||
assert check_data(X, config) == True, "Data is not valid."
|
||||
|
||||
Reference in New Issue
Block a user