feat(training): 添加训练模块基础架构
实现 Commit 1:训练模块基础架构 新增文件: - src/training/__init__.py - 主模块导出 - src/training/components/__init__.py - components 子模块导出 - src/training/components/base.py - BaseModel/BaseProcessor 抽象基类 - src/training/registry.py - 模型和处理器注册中心 - tests/training/test_base.py - 基础架构单元测试 功能特性: - BaseModel: 提供 fit, predict, feature_importance, save/load 接口 - BaseProcessor: 提供 fit, transform, fit_transform 接口 - ModelRegistry/ProcessorRegistry: 支持装饰器风格组件注册 - 支持即插即用的组件扩展机制 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -1,46 +1,26 @@
|
||||
"""ProStock 训练流程模块
|
||||
"""训练模块 - ProStock 量化投资框架
|
||||
|
||||
本模块提供完整的模型训练流程:
|
||||
1. 数据处理:Fillna(0) -> Dropna
|
||||
2. 模型训练:LightGBM分类模型
|
||||
3. 预测选股:每日top5股票池
|
||||
|
||||
使用示例:
|
||||
from src.training import run_training
|
||||
|
||||
# 运行完整训练流程
|
||||
result = run_training(
|
||||
train_start="20180101",
|
||||
train_end="20230101",
|
||||
test_start="20230101",
|
||||
test_end="20240101",
|
||||
top_n=5,
|
||||
output_path="output/top_stocks.tsv"
|
||||
)
|
||||
|
||||
因子使用:
|
||||
from src.factors import MovingAverageFactor, ReturnRankFactor
|
||||
|
||||
ma5 = MovingAverageFactor(period=5) # 5日移动平均
|
||||
ma10 = MovingAverageFactor(period=10) # 10日移动平均
|
||||
ret5 = ReturnRankFactor(period=5) # 5日收益率排名
|
||||
提供模型训练、数据处理和评估的完整流程。
|
||||
"""
|
||||
|
||||
from src.training.pipeline import (
|
||||
create_pipeline,
|
||||
predict_top_stocks,
|
||||
prepare_data,
|
||||
run_training,
|
||||
save_top_stocks,
|
||||
train_model,
|
||||
# 基础抽象类
|
||||
from src.training.components.base import BaseModel, BaseProcessor
|
||||
|
||||
# 注册中心
|
||||
from src.training.registry import (
|
||||
ModelRegistry,
|
||||
ProcessorRegistry,
|
||||
register_model,
|
||||
register_processor,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# 管道函数
|
||||
"prepare_data",
|
||||
"create_pipeline",
|
||||
"train_model",
|
||||
"predict_top_stocks",
|
||||
"save_top_stocks",
|
||||
"run_training",
|
||||
# 基础抽象类
|
||||
"BaseModel",
|
||||
"BaseProcessor",
|
||||
# 注册中心
|
||||
"ModelRegistry",
|
||||
"ProcessorRegistry",
|
||||
"register_model",
|
||||
"register_processor",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user