03_行销(Marketing)里用决策树来做转换率 (Conversion Rate)预测

行销(Marketing)里用决策树来做转换率 (Conversion Rate)预测

我们在01_行销(Marketing)里的有用的KPI-转换率 (Conversion Rate) 文章中介绍了什么是转换率。在这篇里我还是用银行的数据来演示怎么用决策树来做转换率预测。从而可以帮我们很好地看看到底哪些因素导致了顾客的转换。逻辑回归模型通过找到最佳估计事件发生对数几率的特征变量的线性组合来从数据中学习。顾名思义,决策树是通过生长一棵树来从数据中学习的。在下一节中,我们将讨论决策树模型如何增长以及如何构建树,但是逻辑回归和决策树模型之间的主要区别在于,逻辑回归算法会在决策树中搜索单个最佳线性边界。特征集,而决策树算法则对数据进行分区,以查找发生事件的可能性很高的数据子组。

对于决策树,我们一般有两个指标来做树的分枝。基尼杂质 (Gini impurity)和熵信息增益 (Entropy information gain)。简而言之,Gini杂质测量的是分区的不纯,熵信息增益的测量是通过使用测试的标准将数据分割得到的信息量。
在这里插入图片描述
在这里插入图片描述
在这篇里,我会继续用Kaggle的数据来演示怎么用决策树做预测分类模型。数据来源于 bank-full.csv

# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
/kaggle/input/bank-marketing-dataset/bank-full.csv

Load the packages

import matplotlib.pyplot as plt
import pandas as pd
from sklearn import tree
import graphviz
%matplotlib inline

Load the data

df = pd.read_csv('../input/bank-marketing-dataset/bank-full.csv', sep=",")

df.head(3)
age job marital education default balance housing loan contact day month duration campaign pdays previous poutcome y
0 58 management married tertiary no 2143 yes no unknown 5 may 261 1 -1 0 unknown no
1 44 technician single secondary no 29 yes no unknown 5 may 151 1 -1 0 unknown no
2 33 entrepreneur married secondary no 2 yes yes unknown 5 may 76 1 -1 0 unknown no
df['conversion'] = df['y'].apply(lambda x: 0 if x == 'no' else 1)

Data Analysis

Conversion Rate


conversion_rate_df = pd.DataFrame(
    df.groupby('conversion').count()['y'] / df.shape[0] * 100.0
)
conversion_rate_df.T
conversion 0 1
y 88.30152 11.69848

Conversion Rates by Marital Status

conversion_rate_by_marital = df.groupby(
    by='marital'
)['conversion'].sum() / df.groupby(
    by='marital'
)['conversion'].count() * 100.0

                
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值