perf: trim persisted ML fold metadata
This commit is contained in:
+2
-6750
File diff suppressed because it is too large
Load Diff
+9
-1
@@ -164,6 +164,14 @@ def viable_classification_splits(y, splits):
|
||||
yield train_idx, val_idx
|
||||
|
||||
|
||||
def artifact_fold_results(fold_results):
|
||||
"""Strip training-only row indexes from the persisted ML artifact."""
|
||||
return [
|
||||
{key: value for key, value in fold.items() if key not in {"train_idx", "val_idx"}}
|
||||
for fold in fold_results
|
||||
]
|
||||
|
||||
|
||||
def _build_model():
|
||||
return GradientBoostingClassifier(
|
||||
n_estimators=300,
|
||||
@@ -503,7 +511,7 @@ def train_model(rows):
|
||||
"mean_recall": round(float(np.mean(cv_recall)), 4),
|
||||
"validation_method": "purged_expanding_window",
|
||||
"label_horizon_days": LABEL_HORIZON_DAYS,
|
||||
"folds": fold_results,
|
||||
"folds": artifact_fold_results(fold_results),
|
||||
},
|
||||
"training_info": {
|
||||
"n_samples": len(labeled),
|
||||
|
||||
@@ -87,3 +87,21 @@ def test_classification_splits_skip_training_windows_with_one_class():
|
||||
|
||||
assert len(viable) == 1
|
||||
assert viable[0][0].tolist() == [0, 1, 3, 4]
|
||||
|
||||
|
||||
def test_artifact_folds_omit_large_internal_index_arrays():
|
||||
folds = [{
|
||||
"fold": 1,
|
||||
"train_idx": [0, 1],
|
||||
"val_idx": [2, 3],
|
||||
"weights": {"fear_greed": 1.0},
|
||||
"date_ranges": {"validation": "2024-01-01 to 2024-01-02"},
|
||||
}]
|
||||
|
||||
saved = optimizer.artifact_fold_results(folds)
|
||||
|
||||
assert saved == [{
|
||||
"fold": 1,
|
||||
"weights": {"fear_greed": 1.0},
|
||||
"date_ranges": {"validation": "2024-01-01 to 2024-01-02"},
|
||||
}]
|
||||
|
||||
Reference in New Issue
Block a user