fix: reject unprovenanced ML artifacts
This commit is contained in:
+18
-3
@@ -26,7 +26,8 @@ from sklearn.metrics import (
|
||||
from sklearn.model_selection import TimeSeriesSplit
|
||||
from sklearn.preprocessing import StandardScaler
|
||||
|
||||
from scoring.policy import SCORE_BRACKETS, score_in_bracket
|
||||
from scoring.policy import SCORE_BRACKETS, SCORE_VERSION, score_in_bracket
|
||||
from ml.artifacts import ML_ARTIFACT_SCHEMA_VERSION
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
@@ -478,8 +479,12 @@ def train_model(rows):
|
||||
comparison = run_comparison(rows, weights)
|
||||
out_of_sample_comparison = run_out_of_sample_comparison(labeled, fold_results)
|
||||
|
||||
# Build output
|
||||
# Build output. Final weights are fitted on all labeled history for live use;
|
||||
# only the fold weights below are valid for OOS comparisons.
|
||||
trained_at = datetime.now(tz=__import__('datetime').timezone.utc).isoformat()
|
||||
result = {
|
||||
"artifact_schema_version": ML_ARTIFACT_SCHEMA_VERSION,
|
||||
"score_version": SCORE_VERSION,
|
||||
"weights": weights,
|
||||
"feature_importances": {name: round(float(imp), 6) for name, imp in feat_imp},
|
||||
"cv_results": {
|
||||
@@ -501,9 +506,19 @@ def train_model(rows):
|
||||
"date_range": f"{labeled[0]['date']} to {labeled[-1]['date']}",
|
||||
"model": "GradientBoostingClassifier",
|
||||
},
|
||||
"provenance": {
|
||||
"validation_method": "purged_expanding_window",
|
||||
"label_horizon_days": LABEL_HORIZON_DAYS,
|
||||
"weight_scope": "full_history_fit",
|
||||
"training_date_range": {
|
||||
"start": labeled[0]["date"],
|
||||
"end": labeled[-1]["date"],
|
||||
},
|
||||
"trained_at": trained_at,
|
||||
},
|
||||
"comparison": comparison,
|
||||
"out_of_sample_comparison": out_of_sample_comparison,
|
||||
"trained_at": datetime.now(tz=__import__('datetime').timezone.utc).isoformat(),
|
||||
"trained_at": trained_at,
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user