Instructions to use ckcl/mexc_price_model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Adapters
How to use ckcl/mexc_price_model with Adapters:
from adapters import AutoAdapterModel model = AutoAdapterModel.from_pretrained("fill-in-model-name") model.load_adapter("ckcl/mexc_price_model", set_active=True) - Notebooks
- Google Colab
- Kaggle
Create CN_README.md
Browse files- CN_README.md +81 -0
CN_README.md
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 用于 MEXC 价格预测的自定义 Transformer 模型
|
| 2 |
+
|
| 3 |
+
## 模型描述
|
| 4 |
+
|
| 5 |
+
此模型是用于预测 MEXC 合约价格的自定义 Transformer 模型。它由一个嵌入层、后面是多个 Transformer 编码器层以及末尾的全连接层组成,以产生输出。
|
| 6 |
+
|
| 7 |
+
## 模型架构
|
| 8 |
+
|
| 9 |
+
- **输入维度:** 13
|
| 10 |
+
- **模型维度:** 64
|
| 11 |
+
- **头部数量:** 8
|
| 12 |
+
- **层数:** 2
|
| 13 |
+
- **输出维度:** 1
|
| 14 |
+
|
| 15 |
+
## 训练数据
|
| 16 |
+
|
| 17 |
+
该模型基于历史 MEXC 合约交易数据进行训练。特征包括开盘价、收盘价、最高价、最低价、交易量、金额、实际开盘价、实际收盘价、实际最高价、实际最低价和移动平均线。
|
| 18 |
+
|
| 19 |
+
## 训练细节
|
| 20 |
+
|
| 21 |
+
- **优化器**:Adam
|
| 22 |
+
- **学习率**:0.001
|
| 23 |
+
- **损失函数**:均方误差 (MSE)
|
| 24 |
+
- **批次大小**:32
|
| 25 |
+
- **周期数**:50
|
| 26 |
+
|
| 27 |
+
## 用法
|
| 28 |
+
|
| 29 |
+
要使用此模型进行预测,请按照以下步骤操作:
|
| 30 |
+
|
| 31 |
+
1. 加载模型和配置:
|
| 32 |
+
|
| 33 |
+
```python
|
| 34 |
+
import torch
|
| 35 |
+
import torch.nn as nn
|
| 36 |
+
from transformers import AutoConfig
|
| 37 |
+
|
| 38 |
+
class CustomTransformerModel(nn.Module):
|
| 39 |
+
def __init__(self, config):
|
| 40 |
+
super(CustomTransformerModel, self).__init__()
|
| 41 |
+
self.embedding = nn.Linear(config.input_dim, config.model_dim)
|
| 42 |
+
self.encoder_layer = nn.TransformerEncoderLayer(d_model=config.model_dim, nhead=config.num_heads, batch_first=True)
|
| 43 |
+
self.transformer_encoder = nn.TransformerEncoder(self.encoder_layer, num_layers=config.num_layers)
|
| 44 |
+
self.fc = nn.Linear(config.model_dim, config.output_dim)
|
| 45 |
+
|
| 46 |
+
def forward(self, src):
|
| 47 |
+
src = self.embedding(src)
|
| 48 |
+
output = self.transformer_encoder(src)
|
| 49 |
+
output = self.fc(output[:, -1, :])
|
| 50 |
+
return output
|
| 51 |
+
|
| 52 |
+
config = AutoConfig.from_pretrained("your-username/mexc_price_model", config_file_name="BTC_USDT.json")
|
| 53 |
+
model = CustomTransformerModel(config)
|
| 54 |
+
model.load_state_dict(torch.load("model_repo/mexc_price.pth"))
|
| 55 |
+
model.eval()
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
2. 准备输入数据并进行预测:
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
import numpy 作为 np
|
| 62 |
+
从 sklearn.preprocessing 导入 StandardScaler
|
| 63 |
+
|
| 64 |
+
new_data = np.array([
|
| 65 |
+
[1.727087e+09, 63483.9, 63426.2, 63483.9, 63411.6, 1193897.0, 7.575486e+06, 63483.8, 63426.2, 63483.9, 63411.6, 0.00, 0.0, 0.0]
|
| 66 |
+
])
|
| 67 |
+
|
| 68 |
+
scaler = StandardScaler()
|
| 69 |
+
new_data_scaled = scaler.fit_transform(new_data)
|
| 70 |
+
input_tensor = torch.tensor(new_data_scaled, dtype=torch.float32).unsqueeze(1)
|
| 71 |
+
|
| 72 |
+
使用 torch.no_grad():
|
| 73 |
+
prediction = model(input_tensor)
|
| 74 |
+
|
| 75 |
+
predicted_value = prediction.squeeze().item()
|
| 76 |
+
print(f"预测值:{predicted_value}")
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## 许可证
|
| 80 |
+
|
| 81 |
+
此模型根据 [MIT 许可证](LICENSE) 获得许可。
|