5ab1c29c
tangwang
first commit
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# 配置参数调整指南
## 📝 概述
所有默认参数现在都集中在配置文件中,便于统一管理和调整。
## 🎯 主要默认参数
### 在 `config/offline_config.py` 中配置:
```python
# 时间配置
DEFAULT_LOOKBACK_DAYS = 30 # 默认回看天数
DEFAULT_RECENT_DAYS = 7 # 默认最近天数
# i2i算法参数
DEFAULT_I2I_TOP_N = 50 # 默认返回Top N个相似商品
# 兴趣聚合参数
DEFAULT_INTEREST_TOP_N = 1000 # 默认每个key返回Top N个商品
```
## 🔧 调试与生产切换
### 调试阶段(当前配置)
```python
DEFAULT_LOOKBACK_DAYS = 30 # 30天数据,快速验证
DEFAULT_RECENT_DAYS = 7 # 7天最近数据
DEFAULT_I2I_TOP_N = 50 # Top 50
DEFAULT_INTEREST_TOP_N = 1000 # Top 1000
```
**预估运行时间**:30-60分钟
**内存占用**:2-4GB
### 生产环境配置
```python
DEFAULT_LOOKBACK_DAYS = 730 # 2年历史数据,更准确
DEFAULT_RECENT_DAYS = 180 # 半年最近数据
DEFAULT_I2I_TOP_N = 50 # Top 50
DEFAULT_INTEREST_TOP_N = 1000 # Top 1000
```
**预估运行时间**:6-10小时
**内存占用**:8-16GB
## 🚀 使用方式
### 1. 使用默认配置运行
```bash
# 使用配置文件中的默认值(当前为30天)
python3 run_all.py
```
### 2. 临时覆盖默认值
```bash
# 临时使用不同的参数,不修改配置文件
python3 run_all.py --lookback_days 7 --top_n 20
```
### 3. 修改配置文件(推荐)
编辑 `config/offline_config.py`:
```python
# 调试完成后,改为生产配置
DEFAULT_LOOKBACK_DAYS = 730
DEFAULT_RECENT_DAYS = 180
```
然后运行:
```bash
python3 run_all.py
```
## 📊 各脚本的默认参数
所有脚本都会从配置文件读取默认值:
| 脚本 | 参数 | 默认值 | 来源 |
|------|------|--------|------|
| `i2i_swing.py` | `--lookback_days` | 30 | `DEFAULT_LOOKBACK_DAYS` |
| `i2i_swing.py` | `--top_n` | 50 | `DEFAULT_I2I_TOP_N` |
| `i2i_session_w2v.py` | `--lookback_days` | 30 | `DEFAULT_LOOKBACK_DAYS` |
| `i2i_session_w2v.py` | `--top_n` | 50 | `DEFAULT_I2I_TOP_N` |
| `i2i_deepwalk.py` | `--lookback_days` | 30 | `DEFAULT_LOOKBACK_DAYS` |
| `i2i_deepwalk.py` | `--top_n` | 50 | `DEFAULT_I2I_TOP_N` |
| `i2i_content_similar.py` | `--top_n` | 50 | `DEFAULT_I2I_TOP_N` |
| `interest_aggregation.py` | `--lookback_days` | 30 | `DEFAULT_LOOKBACK_DAYS` |
| `interest_aggregation.py` | `--top_n` | 1000 | `DEFAULT_INTEREST_TOP_N` |
## 💡 调试建议
### 第一次运行(验证流程)
```bash
# 使用最小数据量快速验证
python3 run_all.py --lookback_days 7 --top_n 10
```
### 第二次运行(调试参数)
```python
# 修改配置文件为30天
DEFAULT_LOOKBACK_DAYS = 30
```
```bash
python3 run_all.py
```
### 第三次运行(生产环境)
```python
# 修改配置文件为730天
DEFAULT_LOOKBACK_DAYS = 730
DEFAULT_RECENT_DAYS = 180
```
```bash
python3 run_all.py
```
## 🔍 其他可调整的配置
### i2i算法详细配置
在 `offline_config.py` 的 `I2I_CONFIG` 中:
```python
I2I_CONFIG = {
'swing': {
'alpha': 0.5, # swing算法的alpha参数
'threshold1': 0.5, # 交互强度阈值1
'threshold2': 0.5, # 交互强度阈值2
'max_sim_list_len': 300, # 最大相似列表长度
'top_n': 50, # 输出top N个相似商品
},
# ...其他算法配置
}
```
### 兴趣聚合详细配置
```python
INTEREST_AGGREGATION_CONFIG = {
'top_n': 1000, # 每个key生成前N个商品
'time_decay_factor': 0.95, # 时间衰减因子(每30天)
'min_interaction_count': 2, # 最小交互次数
'behavior_weights': {
'click': 1.0,
'addToCart': 3.0,
'addToPool': 2.0,
'contactFactory': 5.0,
'purchase': 10.0,
},
}
```
## 📌 注意事项
1. **调试优先**:先用小数据量(7-30天)验证流程
2. **逐步扩大**:确认无误后再增加到生产数据量
3. **监控资源**:注意内存和磁盘空间使用情况
4. **保存配置**:在配置文件中注释记录不同场景的参数值
## 🎯 快速切换环境
创建不同的配置副本:
```bash
# 备份当前配置
cp config/offline_config.py config/offline_config_debug.py
cp config/offline_config.py config/offline_config_prod.py
# 使用不同配置
cp config/offline_config_debug.py config/offline_config.py # 调试模式
cp config/offline_config_prod.py config/offline_config.py # 生产模式
```
## ✅ 验证配置
查看当前默认值:
```bash
python3 -c "from config.offline_config import *; print(f'LOOKBACK_DAYS: {DEFAULT_LOOKBACK_DAYS}')"
```
查看帮助信息:
```bash
python3 run_all.py --help
```
---
**配置文件位置**: `config/offline_config.py`
**当前默认配置**: 30天调试模式
**建议**: 调试通过后修改为730天生产模式
|