天天看點

Python 資料分析執行個體——Uplift Modeling

作者:昌華量化
Python 資料分析執行個體——Uplift Modeling

Uplift Modeling采用随機科學控制,不僅可以衡量事務行為的有效性,還可以建立預測模型、預測行為的增量響應。它是一種資料挖掘技術,主要應用于金融服務、電信和零售直銷行業,用于追加銷售、交叉銷售、客戶流失和扣除留置。

通常的Propensity Model和Response Model隻是給目标使用者打了個分,并沒有確定模型的結果可以使得活動的提升最大化,它沒有告訴市場營銷人員哪個使用者最有可能提升活動響應,是以需要另一個統計模型來定位那些可以被營銷推廣活動明顯驅動他們偏好響應的使用者,也就是“營銷敏感”使用者。Uplift Model的最終目标就是找到最有可能被營銷活動影響的使用者,進而提升活動的反響(r(test)-r(control)),提升ROI(投資回收率),提升整體的市場響應率。

下面說明進行Uplift Modeling的方法。

(1)建立兩個Logistic模型:

Logit(Ptest(response|X,treatment=1))=a+b*X+c*treatment

Logit(Pcontrol(response|X,treatment=0))=a+b*X

(2)将兩個得分相減,計算Uplift Score:

Score=Ptest(response|X,treatment=1)-Pcontrol(response|X,treatment=0)

訓練樣本:

由于強化學習需要用到的是回報資料,是以訓練樣本的及時、自動更新是比較重要的方面(尤其是label的更新和實時特征的更新),才能展現出強化學習優于機器學習的地方,使用使用者回報的标注樣本來更新訓練樣本庫,可以使得回報及時地得到學習,進而優化算法效果。

【例1】實驗環境是Jupyter Notebook。

我們将使用模拟資料,目标是能夠預測Uplift,即每個人的治療産生的結果機率的差異。

In [1]:%pylab inline
import warnings
warnings.filterwarnings("ignore")
import pandas as pd
Populating the interactive namespace from numpy and matplotlib           

1.加載資料(Loading the data)

Python 資料分析執行個體——Uplift Modeling

2.矯形(Reshaping)

Python 資料分析執行個體——Uplift Modeling

列印結果:

done Node1
done Node2
done Node3
done Node4
done Node5
done Node6
done Node7
done Node8
done Node9
done Node10
done Node11
done Node12
done Node13
done Node14
done Node15
done Node17
done Node18
done Node19
done Node20

In [10]:train_df = df[df["train_test"]=="train"]
test_df = df[df["train_test"]=="test"]

print train_df.shape
print test_df.shape           

列印結果:

(7952, 81)
(2048, 81)           

3.兩類模型(Two model approach)

用目标資料集的結果機率減去控制資料集的結果機率的差來模組化Uplift:

In [11]:target = train_df[train_df["target_control"]=='target']
control = train_df[train_df["target_control"]=='control']

print target.shape
print control.shape           

列印結果:​

(3934, 81)
(4018, 81)
In [12]:target_X = target[features]
control_X = control[features]
target_Y = target[['outcome']]
control_Y = control[['outcome']]
test_X = test_df[features]           

4.訓練(training)

Python 資料分析執行個體——Uplift Modeling

5.得分(scoring)​

In [36]:test_df["proba_outcome_target"] = clf1.predict_proba(test_X)[:,1]
test_df["proba_outcome_control"] = clf2.predict_proba(test_X)[:,1]
# uplift is just the difference.
test_df["uplift_1"]        =         test_df["proba_outcome_target"]  -
test_df["proba_outcome_control"]           

6.類别修正(Class Modification approach)

實作類别修正的方法如下:

· 堆疊目标和控制資料。

· 翻轉控制資料集的目标。

· 在這個目标上訓練一個模型。

· Uplift是預測機率的2倍減去1。

Python 資料分析執行個體——Uplift Modeling

7.儲存預測結果(Save Predictions)

In [44]:test_df.to_csv("/Users/uplift_predictions.csv")