🎯 项目成果: - 准确率: 53.10% (2026年测试集) - 任务类型: 二分类 (预测涨/跌) - 特征: OHLCV + RSI + MACD (9个特征) - 训练数据: 2020-2025年BTC小时数据 (52,351序列) - 测试数据: 2026年1-29日 (484序列) 📊 性能指标: - 精确率: 51.79% - 召回率: 49.36% - F1分数: 0.5054 - 预测分布: 非常平衡 (偏差仅-11个) 🔬 实验历史: - 尝试了5种方案 (回归/分类, 不同数据划分) - 分类任务优于回归任务 (53.10% vs 49.5%) - 全量训练避免了过拟合问题 📦 主要模型文件: - models/checkpoints/dlinear_classification_2026/ - best_model.pt (最佳模型) - preprocessor.pkl (预处理器) - test_2026_results.json (测试结果) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
142 lines
4.0 KiB
Markdown
142 lines
4.0 KiB
Markdown
# Crypto Predictor
|
||
|
||
基于深度学习的加密货币价格预测系统,使用DLinear模型预测BTC未来1小时涨跌方向。
|
||
|
||
## 🎯 项目概况
|
||
|
||
**当前最佳模型性能**:
|
||
- **准确率**: 53.10% ✅ (在2026年测试集上)
|
||
- **任务类型**: 二分类(预测涨/跌)
|
||
- **特征**: OHLCV + RSI + MACD (9个特征)
|
||
- **训练数据**: 2020-2025年BTC小时数据(52,351个序列)
|
||
- **测试数据**: 2026年1-29日(484个序列)
|
||
|
||
## 📊 模型性能指标
|
||
|
||
```
|
||
准确率 (Accuracy): 53.10%
|
||
精确率 (Precision): 51.79%
|
||
召回率 (Recall): 49.36%
|
||
F1分数: 0.5054
|
||
|
||
混淆矩阵:
|
||
预测涨且真涨: 116 (24.0%)
|
||
预测跌且真跌: 141 (29.1%)
|
||
预测涨但真跌: 108 (22.3%)
|
||
预测跌但真涨: 119 (24.6%)
|
||
|
||
预测分布:
|
||
预测上涨: 224 (46.3%)
|
||
预测下跌: 260 (53.7%)
|
||
实际上涨: 235 (48.6%)
|
||
实际下跌: 249 (51.4%)
|
||
偏差: -11个 (非常平衡)
|
||
```
|
||
|
||
## 🏗️ 项目结构
|
||
|
||
```
|
||
crypto_predictor/
|
||
├── data/
|
||
│ ├── fetcher.py # Binance数据获取
|
||
│ ├── preprocessor.py # 数据预处理
|
||
│ └── dataset.py # PyTorch数据集
|
||
├── models/
|
||
│ ├── base.py # 基础模型类
|
||
│ ├── dlinear/
|
||
│ │ └── model.py # DLinear模型实现
|
||
│ └── checkpoints/
|
||
│ └── dlinear_classification_2026/ # 最佳模型(53.10%)
|
||
│ ├── best_model.pt
|
||
│ ├── preprocessor.pkl
|
||
│ └── test_2026_results.json
|
||
├── training/
|
||
│ ├── trainer.py # 训练器
|
||
│ ├── config.py # 训练配置
|
||
│ └── evaluator.py # 评估器
|
||
├── train_classification_full.py # 分类任务训练脚本
|
||
├── test_2026_classification.py # 2026年测试脚本
|
||
└── requirements.txt
|
||
```
|
||
|
||
## 🚀 快速开始
|
||
|
||
### 1. 环境准备
|
||
|
||
```bash
|
||
# 创建conda环境
|
||
conda create -n crypto_pred python=3.12
|
||
conda activate crypto_pred
|
||
|
||
# 安装依赖
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
### 2. 训练模型
|
||
|
||
```bash
|
||
# 使用2020-2025年数据训练分类模型
|
||
python train_classification_full.py
|
||
```
|
||
|
||
### 3. 测试模型
|
||
|
||
```bash
|
||
# 在2026年数据上测试
|
||
python test_2026_classification.py
|
||
```
|
||
|
||
## 📈 使用最佳模型进行预测
|
||
|
||
```python
|
||
import torch
|
||
import pickle
|
||
from data.fetcher import BinanceDataFetcher
|
||
from models.dlinear.model import DLinear
|
||
|
||
# 加载模型
|
||
device = torch.device('mps' if torch.backends.mps.is_available() else 'cpu')
|
||
checkpoint = torch.load('./models/checkpoints/dlinear_classification_2026/best_model.pt',
|
||
map_location=device)
|
||
model = DLinear(checkpoint['config'])
|
||
model.load_state_dict(checkpoint['model_state_dict'])
|
||
model.eval()
|
||
|
||
# 加载预处理器
|
||
with open('./models/checkpoints/dlinear_classification_2026/preprocessor.pkl', 'rb') as f:
|
||
preprocessor = pickle.load(f)
|
||
|
||
# 获取最新数据并预测
|
||
fetcher = BinanceDataFetcher()
|
||
df = fetcher.fetch_ohlcv('BTC', '1h', use_cache=False)
|
||
X, y, _ = preprocessor.preprocess(df, fit=False)
|
||
|
||
# 预测
|
||
with torch.no_grad():
|
||
logits = model(torch.FloatTensor(X[-1:]).to(device))
|
||
prob = torch.sigmoid(logits).item()
|
||
prediction = "上涨" if prob > 0.5 else "下跌"
|
||
|
||
print(f"预测: {prediction} (概率: {prob:.2%})")
|
||
```
|
||
|
||
## 🔬 实验历史
|
||
|
||
| 方案 | 任务类型 | 数据划分 | 准确率 | 主要问题 |
|
||
|------|---------|---------|--------|---------|
|
||
| 1 | 回归(收益率) | 95:5 | 50.23% | 接近随机 |
|
||
| 2 | 回归(收益率) | 直接2026 | 49.48% | 偏向预测上涨 |
|
||
| 3 | 回归(价格) | 直接2026 | 49.48% | MAPE 0.42% |
|
||
| 4 | 回归(价格) | 8:1:1 | 49.64% | 90%预测下跌 |
|
||
| **5** | **分类(涨跌)** | **全量训练** | **53.10%** ✅ | **预测平衡** |
|
||
|
||
## ⚠️ 注意事项
|
||
|
||
1. **53.10%准确率说明**:仅比随机猜测高3.1%,适合小仓位测试
|
||
2. **1小时预测的局限性**:价格变化接近随机游走,技术指标效果有限
|
||
3. **数据要求**:需要至少169小时的历史数据
|
||
|
||
## 📄 许可
|
||
|
||
MIT License
|