完成模型更新

This commit is contained in:
2026-06-24 12:19:08 +08:00
parent ee8fc60eae
commit 6494f43ddd
22 changed files with 4029 additions and 271 deletions
+19 -10
View File
@@ -1,5 +1,5 @@
"""
grid_seeker v6.6 三级模型推理管道
grid_seeker v6.7r3 三级模型推理管道
Rank → Top → Stacking → stacking_probability (最终排序)
"""
import pickle
@@ -18,7 +18,7 @@ from core.logger import LogLevel, PrintLog
# ============================================================
# Rank 模型输入特征 (52维, v3.4, 直接从模型文件的 selected_features 读取)
# Rank 模型输入特征 (56维 v6.7/v3.4, 同时支持 feat_names 和 selected_features)
# ============================================================
def _get_rank_features() -> list:
import pickle
@@ -27,17 +27,26 @@ def _get_rank_features() -> list:
with open(path, 'rb') as f:
obj = pickle.load(f)
if isinstance(obj, dict):
sf = obj.get('selected_features', [])
# v6.7r3 使用 feat_names, v6.6 使用 selected_features
sf = obj.get('feat_names', []) or obj.get('selected_features', [])
if sf:
return sf
raise RuntimeError("无法从 rank.pkl 读取 selected_features")
raise RuntimeError("无法从 rank.pkl 读取 feat_names 或 selected_features")
RANK_FEATURE_COLS = _get_rank_features()
# Top/Stacking 模型只用 52 维基础特征(不含 v6.7 新增的4维)
# v6.7 新增: vol_decay_5d, grid_touch_relative_10d, vol_decay_x_grid_balance, vol_decay_x_dist_lower
_V67_NEW_FEATS = {
'vol_decay_5d', 'grid_touch_relative_10d',
'vol_decay_x_grid_balance', 'vol_decay_x_dist_lower'
}
BASE_52_COLS = [f for f in RANK_FEATURE_COLS if f not in _V67_NEW_FEATS]
class GridSeekerPipeline:
"""
grid_seeker v6.6 三级模型评分管道。
grid_seeker v6.7r3 三级模型评分管道。
Usage:
engine = GridSeekerPipeline()
@@ -120,7 +129,7 @@ class GridSeekerPipeline:
DataFrame indexed by stock_code, 含 stacking_probability / rank 等列,
按 stacking_probability 降序排列
"""
PrintLog(LogLevel.INFO, f'[scorer] ===== grid_seeker v6.6 评分开始 ({trade_date}) =====')
PrintLog(LogLevel.INFO, f'[scorer] ===== grid_seeker v6.7r3 评分开始 ({trade_date}) =====')
# 1. 特征工程
pipeline = FeaturePipeline(trade_date)
@@ -140,16 +149,16 @@ class GridSeekerPipeline:
self.rank_model, feature_df, RANK_FEATURE_COLS
)
# 3. Stage 2: Top 模型 → top_elite_prob (53维 = 52 + rank_predicted_rounds)
# 3. Stage 2: Top 模型 → top_elite_prob (53维 = 52基础 + rank)
PrintLog(LogLevel.INFO, '[scorer] Stage 2/3: Top 模型...')
top_cols = RANK_FEATURE_COLS + ['rank_predicted_rounds']
top_cols = BASE_52_COLS + ['rank_predicted_rounds']
feature_df['top_elite_prob'] = self._predict_with_model(
self.top_model, feature_df, top_cols
)
# 4. Stage 3: Stacking 模型 → stacking_probability (54维 = 52 + rank + top)
# 4. Stage 3: Stacking 模型 → stacking_probability (55维 = 52基础 + rank + top)
PrintLog(LogLevel.INFO, '[scorer] Stage 3/3: Stacking 模型...')
stk_cols = RANK_FEATURE_COLS + ['rank_predicted_rounds', 'top_elite_prob']
stk_cols = BASE_52_COLS + ['rank_predicted_rounds', 'top_elite_prob']
feature_df['stacking_probability'] = self._predict_with_model(
self.stacking_model, feature_df, stk_cols
)