{"id":5263,"date":"2024-08-23T16:06:36","date_gmt":"2024-08-23T07:06:36","guid":{"rendered":"https:\/\/blog.since2020.jp\/?p=5263"},"modified":"2024-08-23T16:07:13","modified_gmt":"2024-08-23T07:07:13","slug":"uplift_modeling_marketing","status":"publish","type":"post","link":"https:\/\/since2020.jp\/media\/uplift_modeling_marketing\/","title":{"rendered":"Uplift Modeling\u3092\u7528\u3044\u305f\u52b9\u679c\u7684\u306a\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u6226\u7565\u306e\u69cb\u7bc9"},"content":{"rendered":"\n<p>\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u30ad\u30e3\u30f3\u30da\u30fc\u30f3\u306e\u52b9\u679c\u3092\u6700\u5927\u5316\u3059\u308b\u305f\u3081\u306b\u3001Uplift Modeling\u306f\u975e\u5e38\u306b\u6709\u529b\u306a\u624b\u6cd5\u3067\u3059\u3002\u672c\u30d6\u30ed\u30b0\u3067\u306f\u3001Uplift Modeling\u306e\u5b9f\u88c5\u624b\u9806\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u30ad\u30e3\u30f3\u30da\u30fc\u30f3\u306e\u52b9\u679c\u3092\u6700\u5927\u5316\u3059\u308b\u305f\u3081\u306b\u3001Uplift Modeling\u306f\u975e\u5e38\u306b\u6709\u529b\u306a\u624b\u6cd5\u3067\u3059\u3002\u672c\u30d6\u30ed\u30b0\u3067\u306f\u3001Uplift Modeling\u306e\u5b9f\u88c5\u624b\u9806\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n<h2>\u74b0\u5883\u8a2d\u5b9a<\/h2>\n<p>\u307e\u305a\u3001\u30c7\u30fc\u30bf\u3092\u6e96\u5099\u3057\u307e\u3059\u3002Uplift\u30e2\u30c7\u30ea\u30f3\u30b0\u306b\u306f\u3001\u4ecb\u5165\uff08Treatment\uff09\u3068\u5bfe\u7167\uff08Control\uff09\u306e\u30c7\u30fc\u30bf\u304c\u5fc5\u8981\u3067\u3059\u3002\u5404\u30b5\u30f3\u30d7\u30eb\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u60c5\u5831\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\r\n<p>\u3000\u4ecb\u5165\u306e\u6709\u7121\uff08Treatment\/Control\uff09<\/p>\r\n<p>\u3000\u9867\u5ba2\u306e\u7279\u5fb4\u91cf\uff08\u4f8b\uff1a\u5e74\u9f62\u3001\u8cfc\u8cb7\u5c65\u6b74\u306a\u3069\uff09<\/p>\r\n<p>\u3000\u7d50\u679c\u5909\u6570\uff08\u4f8b\uff1a\u8cfc\u5165\u306e\u6709\u7121\uff09<\/p>\r\n<p>\u4eca\u56de\u306fGoogle Colab\u4e0a\u3067\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n\n<h2>\u5b9f\u884c\u624b\u9806<\/h2>\n<p>\u4ecb\u5165\u3092\u53d7\u3051\u305f\u30b0\u30eb\u30fc\u30d7\u306e\u7d50\u679c\u3092\u4e88\u6e2c\u3059\u308b\u30e2\u30c7\u30eb\u3068\u4ecb\u5165\u3092\u53d7\u3051\u3066\u3044\u306a\u3044\u30b0\u30eb\u30fc\u30d7\u306e\u7d50\u679c\u3092\u4e88\u6e2c\u3059\u308b\u30e2\u30c7\u30eb\u3092\u69cb\u7bc9\u3057\u3001\u6700\u5f8c\u306b\u305d\u306e2\u3064\u306e\u30e2\u30c7\u30eb\u306e\u4e88\u6e2c\u7d50\u679c\u306e\u5dee\u3092\u53d6\u308b\u3053\u3068\u3067Uplift\u3092\u8a08\u7b97\u3057\u307e\u3059\u3002<\/p>\r\n<p>\u4ee5\u4e0b\u306b\u30b3\u30fc\u30c9\u3092\u8a18\u8f09\u3057\u307e\u3059\u3002<\/p>\r\n<p>\u306f\u3058\u3081\u306b\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import pandas as pd\r\nimport numpy as np\r\nfrom sklearn.model_selection import train_test_split\r\nfrom sklearn.ensemble import RandomForestClassifier\r\nfrom sklearn.linear_model import LogisticRegression\r\nfrom sklearn.metrics import roc_auc_score<\/code><\/pre>\r\n<\/div>\r\n<p>\u4e0b\u8a18\u306e\u30e2\u30c7\u30eb\u3092\u4f7f\u7528\u3057\u3066\u305d\u308c\u305e\u308c\u5b9f\u88c5\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\r\n<p>\u4ecb\u5165\u3092\u53d7\u3051\u305f\u30b0\u30eb\u30fc\u30d7\uff1a\u30e9\u30f3\u30c0\u30e0\u30d5\u30a9\u30ec\u30b9\u30c8<\/p>\r\n<p>\u4ecb\u5165\u3092\u53d7\u3051\u3066\u3044\u306a\u3044\u30b0\u30eb\u30fc\u30d7\uff1a\u30ed\u30b8\u30b9\u30c6\u30a3\u30af\u56de\u5e30<\/p>\r\n<p>&nbsp;<\/p>\r\n<p>\u4ecb\u5165\u3092\u53d7\u3051\u305f\u30b0\u30eb\u30fc\u30d7<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>#\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\r\ndata = pd.read_csv(\"data.csv\")\r\n\r\n#\u7279\u5fb4\u91cf\u3068\u30e9\u30d9\u30eb\u306e\u8a2d\u5b9a\r\nX = data.drop([\"treatment\",\"outcome\"],axis = 1)<\/code>y = data[\"outcome\"] treatment = data[\"treatment\"] #\u30c7\u30fc\u30bf\u306e\u5206\u5272 X_train,X_test,y_train,y_test,treatment_train,treatment_test = train_test_split(X,y,treatment,test_size = 0.2,random_state = 42) #\u4ecb\u5165\u30b0\u30eb\u30fc\u30d7\u3068\u5bfe\u7167\u30b0\u30eb\u30fc\u30d7\u306e\u30c7\u30fc\u30bf\u5206\u5272 X_train_treatment = X_train[treatment_train == 1] y_train_treatment = y_train[treatment_train == 1] X_train_control = X_train[treatment_train == 0] y_train_control = y_train[treatment_train == 0] model_treatment = RandomForestClassifier(random_state = 42) model_treatment.fit(X_train_treatment,y_train_treatment) model_control = RandomForestClassifier(random_state = 42) model_control.fit(X_train_control,y_train_control) #\u4e88\u6e2c pred_treatment = model_treatment.predict_proba(X_test)[:,1] pred_control = model_control.predict_proba(X_test)[:,1] #uplift\u306e\u8a08\u7b97 uplift = pred_treatment - pred_control<\/pre>\r\n<\/div>\r\n<p>\u4ecb\u5165\u3092\u53d7\u3051\u3066\u306a\u3044\u30b0\u30eb\u30fc\u30d7<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>#\u7279\u5fb4\u91cf\u306b\u4ecb\u5165\u306e\u6709\u7121\u3092\u8ffd\u52a0\r\nX_traina[\"treatment\"] = treatment_train\r\nX_test[\"treatment\"] = treatment_test\r\n\r\n#\u30e2\u30c7\u30eb\u306e\u69cb\u7bc9\r\nmodel = LogisticRegression(random_state = 42)\r\nmodel.fit(X_train,y_train)\r\n\r\n#\u4e88\u6e2c\r\npred = model.predict_proba(X_test)[:,1]\r\n\r\n#uplift\u306e\u8a08\u7b97\uff08\u7c21\u7565\u5316\u306e\u305f\u3081\u3001\u51e6\u7406\u5f8c\u306b\u5206\u3051\u3066\u8a08\u7b97\u3059\u308b\uff09\r\nuplift = pred[treatment_test == 1] - pred[treatment_test == 0]<\/code><\/pre>\r\n<\/div>\r\n<p>\u6700\u5f8c\u306b\u4e88\u6e2c\u7cbe\u5ea6\u3092\u8a55\u4fa1\u3057\u307e\u3059\u3002<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>#uplift\u306e\u4e88\u6e2c\u7cbe\u5ea6\u3092\u8a55\u4fa1\r\nauc_score = roc_auc_score(y_test,uplift)\r\nprint(\"AUC Score:\",auc_score)<\/code><\/pre>\r\n<\/div>\r\n<p>\u3053\u306e\u3088\u3046\u306a\u624b\u9806\u3092\u8e0f\u3080\u3053\u3068\u3067Uplift\u30e2\u30c7\u30ea\u30f3\u30b0\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059<\/p>\n\n<h2>\u307e\u3068\u3081<\/h2>\n<p>Uplift Modeling\u306f\u3001\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u6d3b\u52d5\u306e\u52b9\u7387\u3092\u5927\u5e45\u306b\u5411\u4e0a\u3055\u305b\u308b\u53ef\u80fd\u6027\u3092\u79d8\u3081\u305f\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002\u4eca\u56de\u306e\u30d6\u30ed\u30b0\u3067\u306f\u3001Uplift Modeling\u306e\u57fa\u672c\u7684\u306a\u7406\u8ad6\u3068\u5b9f\u88c5\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3057\u305f\u3002\u3053\u306e\u624b\u6cd5\u3092\u6d3b\u7528\u3059\u308b\u3053\u3068\u3067\u3001\u9867\u5ba2\u306e\u53cd\u5fdc\u3092\u3088\u308a\u7cbe\u78ba\u306b\u4e88\u6e2c\u3057\u3001\u30ad\u30e3\u30f3\u30da\u30fc\u30f3\u306e\u6210\u679c\u3092\u6700\u5927\u5316\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u662f\u975e\u3001\u3053\u306e\u77e5\u8b58\u3092\u5b9f\u8df5\u306b\u6d3b\u304b\u3057\u3001\u3088\u308a\u52b9\u679c\u7684\u306a\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u6226\u7565\u3092\u69cb\u7bc9\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u30ad\u30e3\u30f3\u30da\u30fc\u30f3\u306e\u52b9\u679c\u3092\u6700\u5927\u5316\u3059\u308b\u305f\u3081\u306b\u3001Uplift Modeling\u306f\u975e\u5e38\u306b\u6709\u529b\u306a\u624b\u6cd5\u3067\u3059\u3002\u672c\u30d6\u30ed\u30b0\u3067\u306f\u3001Uplift Modeling\u306e\u5b9f\u88c5\u624b\u9806\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002 \u306f\u3058\u3081\u306b \u30de\u30fc\u30b1\u30c6\u30a3\u30f3\u30b0\u30ad\u30e3\u30f3\u30da\u30fc\u30f3\u306e\u52b9\u679c\u3092 [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":4262,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","swell_btn_cv_data":"","footnotes":"","_wp_rev_ctl_limit":""},"categories":[1246],"tags":[331,679,678,33],"class_list":["post-5263","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-infrastructure","tag-python","tag-sklearn","tag-uplift-modeling","tag-33"],"_links":{"self":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/5263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/comments?post=5263"}],"version-history":[{"count":0,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/5263\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media\/4262"}],"wp:attachment":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media?parent=5263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/categories?post=5263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/tags?post=5263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}