fix: train valid purged ML artifacts
This commit is contained in:
+10
-2
@@ -156,6 +156,14 @@ def purged_time_series_splits(rows, n_splits=VALIDATION_SPLITS,
|
||||
yield np.array(purged_train, dtype=int), np.array(val_idx, dtype=int)
|
||||
|
||||
|
||||
def viable_classification_splits(y, splits):
|
||||
"""Yield only folds whose training window contains both target classes."""
|
||||
for train_idx, val_idx in splits:
|
||||
if len(np.unique(y[train_idx])) < 2:
|
||||
continue
|
||||
yield train_idx, val_idx
|
||||
|
||||
|
||||
def _build_model():
|
||||
return GradientBoostingClassifier(
|
||||
n_estimators=300,
|
||||
@@ -377,12 +385,12 @@ def train_model(rows):
|
||||
cv_recall = []
|
||||
fold_results = []
|
||||
|
||||
splits = list(purged_time_series_splits(
|
||||
splits = list(viable_classification_splits(y, purged_time_series_splits(
|
||||
labeled,
|
||||
n_splits=VALIDATION_SPLITS,
|
||||
label_horizon_days=LABEL_HORIZON_DAYS,
|
||||
embargo_days=0,
|
||||
))
|
||||
)))
|
||||
if not splits:
|
||||
log.error("No viable purged validation splits. Need more history for %dd label horizon.",
|
||||
LABEL_HORIZON_DAYS)
|
||||
|
||||
Reference in New Issue
Block a user