11# TalkingData 广告欺诈检测(OpenMLDB + XGboost)
22
3- 我们将演示如何使用 [ OpenMLDB] ( https://github.com/4paradigm/OpenMLDB ) 与其他开源软件一起开发一个完整的机器学习应用程序 ,完成 TalkingData 广告欺诈检测挑战(有关此挑战的更多信息请参阅 [ Kaggle ] ( https://www.kaggle.com/c/talkingdata-adtracking-fraud-detection/overview ) ) 。
3+ 本文将演示如何使用 OpenMLDB 与开源软件 XGboost 联合开发一个完整的机器学习应用 ,完成 [ TalkingData 广告欺诈检测挑战] ( https://www.kaggle.com/c/talkingdata-adtracking-fraud-detection/overview ) 。
44
5+ ## 准备
56
7+ 本文基于 OpenMLDB CLI 进行开发和部署,首先需要下载样例数据并且启动 OpenMLDB CLI。推荐使用 Docker 镜像来快速体验。
68
9+ - Docker 版本:>= 18.03
710
8- ## 1 准备工作
11+ ### 启动 OpenMLDB 镜像
912
10- ### 1.1 下载并安装OpenMLDB
13+ 在命令行执行以下命令启动 OpenMLDB 镜像
1114
12- #### 1.1.1 在 Docker 中运行
13-
14- 我们建议您使用docker来运行此 Demo。OpenMLDB 和依赖项都已安装完毕。
15-
16- ** 启动 Docker**
17-
18- ```
15+ ``` bash
1916docker run -it 4pdosc/openmldb:0.9.2 bash
2017```
2118
22- #### 1.1.2 在本地运行
19+ ### 安装依赖
2320
24- 下载 OpenMLDB 服务器 pkg,版本>=0.5.0。
21+ 执行如下命令安装所有依赖项:
2522
26- 安装所有依赖项:
27-
28- ```
23+ ``` bash
2924pip install pandas xgboost==1.4.2 sklearn tornado " openmldb>=0.5.0" requests
3025```
3126
32- ### 1.2 准备数据
27+ ### 准备数据
3328
34- 我们只使用 ` train.csv ` 的前10000行作为示例数据,请参见 [ train\_ sample.csv] ( https://github.com/4paradigm/OpenMLDB/tree/main/demo/talkingdata-adtracking-fraud-detection ) 。
29+ 本例使用 ` train.csv ` 的前 10000 行作为示例数据,详情请参见代码 [ train\_ sample.csv] ( https://github.com/4paradigm/OpenMLDB/tree/main/demo/talkingdata-adtracking-fraud-detection ) 。
3530
36- 如果你想要测试完整数据,请通过以下方式下载
31+ 如果你想要测试完整数据,请通过以下方式下载:
3732
38- ```
33+ ``` bash
3934kaggle competitions download -c talkingdata-adtracking-fraud-detection
4035```
4136
42- 并将数据解压缩到 ` demo/talkingdata-adtracking-fraud-detection/data ` 。然后调用 [ train\_ and\_ serve.py] ( https://github.com/4paradigm/OpenMLDB/blob/main/demo/talkingdata-adtracking-fraud-detection/train_and_serve.py ) 中的 ` cut_data() ` 方法,制作新的csv样本用于训练 。
37+ 并将数据解压缩到 ` demo/talkingdata-adtracking-fraud-detection/data ` 。然后调用 [ train\_ and\_ serve.py] ( https://github.com/4paradigm/OpenMLDB/blob/main/demo/talkingdata-adtracking-fraud-detection/train_and_serve.py ) 中的 ` cut_data() ` 方法,制作新的 CSV 数据样本用于训练 。
4338
4439
45- ### 1.3 启动 OpenMLDB 集群
40+ ### 启动 OpenMLDB 集群
4641
47- ```
42+ ``` bash
4843/work/init.sh
4944```
5045
51- ### 1.4 启动预测服务器
46+ ### 启动预测服务器
5247
53- 即使您还没有部署预测服务器,您也可以启动它,使用选项 ` --no-init ` 。
48+ 即使还没有部署预测服务器,你也可以使用选项 ` --no-init ` 启动
5449
55- ```
50+ ``` bash
5651python3 /work/talkingdata/predict_server.py --no-init > predict.log 2>&1 &
5752```
5853
5954
6055``` {tip}
61- - 训练完毕后,您可以发送 post 请求至 `<ip>:<port>/update` 更新预测服务器。
62- - 您可以运行 `pkill -9 python3` 命令,关闭后台预测服务器。
56+ - 训练完毕后,可以发送 post 请求至 `<ip>:<port>/update` 更新预测服务器。
57+ - 可以运行 `pkill -9 python3` 命令,关闭后台预测服务器。
6358```
6459
6560
66- ## 2 训练并应用
61+ ## 训练并应用
6762
6863```
6964cd /work/talkingdata
7065python3 train_and_serve.py
7166```
7267
73- 我们使用 OpenMLDB 提取特征,并通过 xgboost 进行训练 ,请参见[ train\_ and\_ serve.py] ( https://github.com/4paradigm/OpenMLDB/blob/main/demo/talkingdata-adtracking-fraud-detection/train_and_serve.py ) 。
68+ 使用 OpenMLDB 提取特征,并通过 XGboost 训练机器学习模型 ,请参见 [ train\_ and\_ serve.py] ( https://github.com/4paradigm/OpenMLDB/blob/main/demo/talkingdata-adtracking-fraud-detection/train_and_serve.py ) 。程序具体内容有如下步骤:
7469
75701 . 将数据加载到离线存储
76- 2 . 离线特征提取;
71+ 2 . 离线特征提取
7772 * ip-day-hour 组合的点击次数 -> 窗口期 1h
7873 * ip-app 组合的点击次数 -> 无限窗口期
7974 * ip-app-os 组合的点击次数 -> 无限窗口期
@@ -82,21 +77,26 @@ python3 train_and_serve.py
82775 . 加载数据到在线存储
83786 . 更新预测服务器上的模型
8479
85- ## 3 预测
80+ ## 预测
8681
87- 向预测服务器发送post请求 ` <ip>:<port>/predict ` 即可进行一次预测。或者您也可以运行下面的python脚本 。
82+ 向预测服务器发送 POST 请求 ` <ip>:<port>/predict ` 即可进行一次预测。或者也可以运行下面的 Python 脚本 。
8883
89- ```
84+ ``` bash
9085python3 predict.py
9186```
9287
93- ## 4 提示
88+ ## 提示
9489
95- 预构建的 xgboost python wheel 可能与您计算机中的 openmldb python sdk 不兼容,可能会出现该报错:
96- ` train\_and\_serve.py core dump at SetGPUAttribute... `
90+ 预构建的 XGboost Python Wheel 可能与您计算机中的 OpenMLDB Python SDK 不兼容,可能会出现该报错:` train\_and\_serve.py core dump at SetGPUAttribute... `
9791
98- 通过源代码构建xgboost可解决该问题:进入 xgboost 源代码所在的目录,并执行
99- ` cd python-package && python setup.py install `
92+ 通过源代码构建 XGboost 可解决该问题:进入 XGhboost 源代码所在的目录,并执行:
10093
101- 或者构建 wheel :
102- ` python setup.py bdist_wheel `
94+ ``` bash
95+ cd python-package && python setup.py install
96+ ```
97+
98+ 或者构建 wheel:
99+
100+ ``` bash
101+ python setup.py bdist_wheel
102+ ```
0 commit comments