# 烟草推荐模型部署文档 ## 1、配置文件说明: - ### database_config.yaml  这个是数据配置文件 ``` mysql: host: 'rm-t4n6rz18y4t5x47y70o.mysql.singapore.rds.aliyuncs.com' port: 3036 db: 'brand_cultivation' user: 'xxxxx' passwd: 'xxxxx' redis: host: 'r-t4nb4n9i8je7u6ogk1pd.redis.singapore.rds.aliyuncs.com' port: 5000 db: 10 passwd: 'xxxxx' ``` - ### crontab 定时任务配置文件 ``` # START CRON JOB 1 2 * * * python /app/app.pyc --run_all # END CRON JOB ```   ## 2、模型启动配置说明: ### app.py ``` parser.add_argument("--run_all", action='store_true') parser.add_argument("--run_hot", action='store_true') parser.add_argument("--run_itemcf", action='store_true') parser.add_argument("--run_itemcf_inference", action='store_true') parser.add_argument("--city_uuid", type=str, help="City UUID for filtering data") ``` ### 总共有4种启动模式分别是: 1\. 启动热度召回和协同过滤         2. 启动热度召回         3. 启动协同过滤         4. 启动系统过滤推理 ## 3、GBDT LR模型训练推理启动 ### gbdt_lr.py ``` parser.add_argument("--run_train", action='store_true') parser.add_argument("--recommend", action='store_true') parser.add_argument("--importance", action='store_true') parser.add_argument("--city_uuid", type=str, default='00000000000000000000000011445301') parser.add_argument("--product_id", type=str, default='110102') ``` ### gbdt_lr总共3个功能: 1\. 启动gbdt_lr训练 python -m gbdt_lr --run_train --city_uuid "00000000000000000000000011445301"         2. 根据城市id和product_id进行推荐,需要指定city_uuid、product_id。 python -m gbdt_lr --recommend --city_uuid "00000000000000000000000011445301" --product_id '110102'         3. 获取指定城市的特征重要性指标。 python -m gbdt_lr --importance --city_uuid "00000000000000000000000011445301" 注意:在数据准备阶段,会将训练数据保存到./models/rank/data/gbdt_data.csv中 模型文件会存放在 ./models/rank/weights/city_uuid/model.pkl 重要性指标会存放在 ./models/rank/weights/下,分别是商户指标重要性和卷烟指标重要性 ## 4、模型docker运行配置说明: ### docker镜像是:registry.cn-hangzhou.aliyuncs.com/hexiaoshi/brandcultivation:0.0.1 ```yaml docker run --name BrandCultivation -d -v /export/brandcultivation/crontab:/etc/cron.d/crontab -v /export/brandcultivation/database_config.yaml:/app/config/database_config.yaml registry.cn-hangzhou.aliyuncs.com/hexiaoshi/brandcultivation:0.0.1 ``` ## 5、模型kubernetes运行配置说明 yaml文件如下: ```yaml apiVersion: apps/v1 kind: Deployment metadata: name: brandcultivation namespace: default labels: app: brandcultivation spec: selector: matchLabels: app: brandcultivation replicas: 1 strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: labels: app: brandcultivation spec: containers: - name: brandcultivation image: registry.cn-hangzhou.aliyuncs.com/hexiaoshi/brandcultivation:0.0.1 imagePullPolicy: IfNotPresent resources: requests: cpu: 4000m memory: 4096Mi ephemeral-storage: 20Gi limits: cpu: 4000m memory: 4096Mi ephemeral-storage: 20Gi ports: - containerPort: 80 name: brandcultivation volumeMounts: - name: localtime mountPath: /etc/localtime - name: config mountPath: /app/config/database_config.yaml subPath: database_config.yaml - name: config mountPath: /etc/cron.d/crontab subPath: crontab - name: localtime hostPath: path: /usr/share/zoneinfo/Asia/Shanghai - name: config configMap: name: brandcultivation restartPolicy: Always --- kind: ConfigMap apiVersion: v1 metadata: name: brandcultivation namespace: default data: database_config.yaml: | mysql: host: 'rm-t4n6rz18y4t5x47y70o.mysql.singapore.rds.aliyuncs.com' port: 3036 db: 'brand_cultivation' user: 'BrandCultivation' passwd: '8BfWBc18NBXl#CMd' redis: host: 'r-t4nb4n9i8je7u6ogk1pd.redis.singapore.rds.aliyuncs.com' port: 5000 db: 10 passwd: 'gHmNkVBd88sZybj' crontab: | # START CRON JOB 1 2 * * * python /app/app.pyc # END CRON JOB ```