电信公司churn数据客户流失k近邻(knn)模型预测分析

简介: 电信公司churn数据客户流失k近邻(knn)模型预测分析

Data background

A telephone company is interested in determining which customer characteristics are useful for predicting churn, customers who will leave their service.

The data set  is Churn . The fields are as follows:

 

State

 discrete.

account length

 continuous.

area code

 continuous.

phone number

 discrete.

international plan

 discrete.

voice mail plan

 discrete.

number vmail messages

 continuous.

total day minutes

 continuous.

total day calls

 continuous.

total day charge

 continuous.

total eve minutes

 continuous.

total eve calls

 continuous.

total eve charge

 continuous.

total night minutes

 continuous.

total night calls

 continuous.

total night charge

 continuous.

total intl minutes

 continuous.

total intl calls

 continuous.

total intl charge

 continuous.

number customer service calls

 continuous.

churn

 Discrete

Data Preparation and Exploration

 

1. 查看数据概览
2. 
3. ##      state      account.length    area.code        phone.number
4. ##  WV     : 158   Min.   :  1.0   Min.   :408.0    327-1058:   1
5. ##  MN     : 125   1st Qu.: 73.0   1st Qu.:408.0    327-1319:   1
6. ##  AL     : 124   Median :100.0   Median :415.0    327-2040:   1
7. ##  ID     : 119   Mean   :100.3   Mean   :436.9    327-2475:   1
8. ##  VA     : 118   3rd Qu.:127.0   3rd Qu.:415.0    327-3053:   1
9. ##  OH     : 116   Max.   :243.0   Max.   :510.0    327-3587:   1
10. ##  (Other):4240                                   (Other)  :4994
11. ##  international.plan voice.mail.plan number.vmail.messages
12. ##   no :4527           no :3677       Min.   : 0.000
13. ##   yes: 473           yes:1323       1st Qu.: 0.000
14. ##                                     Median : 0.000
15. ##                                     Mean   : 7.755
16. ##                                     3rd Qu.:17.000
17. ##                                     Max.   :52.000
18. ##
19. ##  total.day.minutes total.day.calls total.day.charge total.eve.minutes
20. ##  Min.   :  0.0     Min.   :  0     Min.   : 0.00    Min.   :  0.0
21. ##  1st Qu.:143.7     1st Qu.: 87     1st Qu.:24.43    1st Qu.:166.4
22. ##  Median :180.1     Median :100     Median :30.62    Median :201.0
23. ##  Mean   :180.3     Mean   :100     Mean   :30.65    Mean   :200.6
24. ##  3rd Qu.:216.2     3rd Qu.:113     3rd Qu.:36.75    3rd Qu.:234.1
25. ##  Max.   :351.5     Max.   :165     Max.   :59.76    Max.   :363.7
26. ##
27. ##  total.eve.calls total.eve.charge total.night.minutes total.night.calls
28. ##  Min.   :  0.0   Min.   : 0.00    Min.   :  0.0       Min.   :  0.00
29. ##  1st Qu.: 87.0   1st Qu.:14.14    1st Qu.:166.9       1st Qu.: 87.00
30. ##  Median :100.0   Median :17.09    Median :200.4       Median :100.00
31. ##  Mean   :100.2   Mean   :17.05    Mean   :200.4       Mean   : 99.92
32. ##  3rd Qu.:114.0   3rd Qu.:19.90    3rd Qu.:234.7       3rd Qu.:113.00
33. ##  Max.   :170.0   Max.   :30.91    Max.   :395.0       Max.   :175.00
34. ##
35. ##  total.night.charge total.intl.minutes total.intl.calls total.intl.charge
36. ##  Min.   : 0.000     Min.   : 0.00      Min.   : 0.000   Min.   :0.000
37. ##  1st Qu.: 7.510     1st Qu.: 8.50      1st Qu.: 3.000   1st Qu.:2.300
38. ##  Median : 9.020     Median :10.30      Median : 4.000   Median :2.780
39. ##  Mean   : 9.018     Mean   :10.26      Mean   : 4.435   Mean   :2.771
40. ##  3rd Qu.:10.560     3rd Qu.:12.00      3rd Qu.: 6.000   3rd Qu.:3.240
41. ##  Max.   :17.770     Max.   :20.00      Max.   :20.000   Max.   :5.400
42. ##
43. ##  number.customer.service.calls     churn
44. ##  Min.   :0.00                   False.:4293
45. ##  1st Qu.:1.00                   True. : 707
46. ##  Median :1.00
47. ##  Mean   :1.57
48. ##  3rd Qu.:2.00
49. ##  Max.   :9.00
50. ##
51.

从数据概览中我们可以发现没有缺失数据,同时可以发现电话号 地区代码是没有价值的变量,可以删去

 

Examine the variables graphically

 

 

从上面的结果中,我们可以看到churn为no的样本数目要远远大于churn为yes的样本,因此所有样本中churn占多数。

 

从上面的结果中,我们可以看到除了emailcode和areacode之外,其他数值变量近似符合正态分布。

1. ##  account.length    area.code     number.vmail.messages total.day.minutes
2. ##  Min.   :  1.0   Min.   :408.0   Min.   : 0.000        Min.   :  0.0
3. ##  1st Qu.: 73.0   1st Qu.:408.0   1st Qu.: 0.000        1st Qu.:143.7
4. ##  Median :100.0   Median :415.0   Median : 0.000        Median :180.1
5. ##  Mean   :100.3   Mean   :436.9   Mean   : 7.755        Mean   :180.3
6. ##  3rd Qu.:127.0   3rd Qu.:415.0   3rd Qu.:17.000        3rd Qu.:216.2
7. ##  Max.   :243.0   Max.   :510.0   Max.   :52.000        Max.   :351.5
8. ##  total.day.calls total.day.charge total.eve.minutes total.eve.calls
9. ##  Min.   :  0     Min.   : 0.00    Min.   :  0.0     Min.   :  0.0
10. ##  1st Qu.: 87     1st Qu.:24.43    1st Qu.:166.4     1st Qu.: 87.0
11. ##  Median :100     Median :30.62    Median :201.0     Median :100.0
12. ##  Mean   :100     Mean   :30.65    Mean   :200.6     Mean   :100.2
13. ##  3rd Qu.:113     3rd Qu.:36.75    3rd Qu.:234.1     3rd Qu.:114.0
14. ##  Max.   :165     Max.   :59.76    Max.   :363.7     Max.   :170.0
15. ##  total.eve.charge total.night.minutes total.night.calls total.night.charge
16. ##  Min.   : 0.00    Min.   :  0.0       Min.   :  0.00    Min.   : 0.000
17. ##  1st Qu.:14.14    1st Qu.:166.9       1st Qu.: 87.00    1st Qu.: 7.510
18. ##  Median :17.09    Median :200.4       Median :100.00    Median : 9.020
19. ##  Mean   :17.05    Mean   :200.4       Mean   : 99.92    Mean   : 9.018
20. ##  3rd Qu.:19.90    3rd Qu.:234.7       3rd Qu.:113.00    3rd Qu.:10.560
21. ##  Max.   :30.91    Max.   :395.0       Max.   :175.00    Max.   :17.770
22. ##  total.intl.minutes total.intl.calls total.intl.charge
23. ##  Min.   : 0.00      Min.   : 0.000   Min.   :0.000
24. ##  1st Qu.: 8.50      1st Qu.: 3.000   1st Qu.:2.300
25. ##  Median :10.30      Median : 4.000   Median :2.780
26. ##  Mean   :10.26      Mean   : 4.435   Mean   :2.771
27. ##  3rd Qu.:12.00      3rd Qu.: 6.000   3rd Qu.:3.240
28. ##  Max.   :20.00      Max.   :20.000   Max.   :5.400
29. ##  number.customer.service.calls
30. ##  Min.   :0.00
31. ##  1st Qu.:1.00
32. ##  Median :1.00
33. ##  Mean   :1.57
34. ##  3rd Qu.:2.00
35. ##  Max.   :9.00

Relationships between variables

从结果中我们可以看到两者之间存在显著的正相关线性关系。

 

Using the statistics node, report

1. ##                               account.length    area.code
2. ## account.length                  1.0000000000 -0.018054187
3. ## area.code                      -0.0180541874  1.000000000
4. ## number.vmail.messages          -0.0145746663 -0.003398983
5. ## total.day.minutes              -0.0010174908 -0.019118245
6. ## total.day.calls                 0.0282402279 -0.019313854
7. ## total.day.charge               -0.0010191980 -0.019119256
8. ## total.eve.minutes              -0.0095913331  0.007097877
9. ## total.eve.calls                 0.0091425790 -0.012299947
10. ## total.eve.charge               -0.0095873958  0.007114130
11. ## total.night.minutes             0.0006679112  0.002083626
12. ## total.night.calls              -0.0078254785  0.014656846
13. ## total.night.charge              0.0006558937  0.002070264
14. ## total.intl.minutes              0.0012908394 -0.004153729
15. ## total.intl.calls                0.0142772733 -0.013623309
16. ## total.intl.charge               0.0012918112 -0.004219099
17. ## number.customer.service.calls  -0.0014447918  0.020920513
18. ##                               number.vmail.messages total.day.minutes
19. ## account.length                        -0.0145746663      -0.001017491
20. ## area.code                             -0.0033989831      -0.019118245
21. ## number.vmail.messages                  1.0000000000       0.005381376
22. ## total.day.minutes                      0.0053813760       1.000000000
23. ## total.day.calls                        0.0008831280       0.001935149
24. ## total.day.charge                       0.0053767959       0.999999951
25. ## total.eve.minutes                      0.0194901208      -0.010750427
26. ## total.eve.calls                       -0.0039543728       0.008128130
27. ## total.eve.charge                       0.0194959757      -0.010760022
28. ## total.night.minutes                    0.0055413838       0.011798660
29. ## total.night.calls                      0.0026762202       0.004236100
30. ## total.night.charge                     0.0055349281       0.011782533
31. ## total.intl.minutes                     0.0024627018      -0.019485746
32. ## total.intl.calls                       0.0001243302      -0.001303123
33. ## total.intl.charge                      0.0025051773      -0.019414797
34. ## number.customer.service.calls         -0.0070856427       0.002732576
35. ##                               total.day.calls total.day.charge
36. ## account.length                   0.0282402279     -0.001019198
37. ## area.code                       -0.0193138545     -0.019119256
38. ## number.vmail.messages            0.0008831280      0.005376796
39. ## total.day.minutes                0.0019351487      0.999999951
40. ## total.day.calls                  1.0000000000      0.001935884
41. ## total.day.charge                 0.0019358844      1.000000000
42. ## total.eve.minutes               -0.0006994115     -0.010747297
43. ## total.eve.calls                  0.0037541787      0.008129319
44. ## total.eve.charge                -0.0006952217     -0.010756893
45. ## total.night.minutes              0.0028044650      0.011801434
46. ## total.night.calls               -0.0083083467      0.004234934
47. ## total.night.charge               0.0028018169      0.011785301
48. ## total.intl.minutes               0.0130972198     -0.019489700
49. ## total.intl.calls                 0.0108928533     -0.001306635
50. ## total.intl.charge                0.0131613976     -0.019418755
51. ## number.customer.service.calls   -0.0107394951      0.002726370
52. ##                               total.eve.minutes total.eve.calls
53. ## account.length                    -0.0095913331     0.009142579
54. ## area.code                          0.0070978766    -0.012299947
55. ## number.vmail.messages              0.0194901208    -0.003954373
56. ## total.day.minutes                 -0.0107504274     0.008128130
57. ## total.day.calls                   -0.0006994115     0.003754179
58. ## total.day.charge                  -0.0107472968     0.008129319
59. ## total.eve.minutes                  1.0000000000     0.002763019
60. ## total.eve.calls                    0.0027630194     1.000000000
61. ## total.eve.charge                   0.9999997749     0.002778097
62. ## total.night.minutes               -0.0166391160     0.001781411
63. ## total.night.calls                  0.0134202163    -0.013682341
64. ## total.night.charge                -0.0166420421     0.001799380
65. ## total.intl.minutes                 0.0001365487    -0.007458458
66. ## total.intl.calls                   0.0083881559     0.005574500
67. ## total.intl.charge                  0.0001593155    -0.007507151
68. ## number.customer.service.calls     -0.0138234228     0.006234831
69. ##                               total.eve.charge total.night.minutes
70. ## account.length                   -0.0095873958        0.0006679112
71. ## area.code                         0.0071141298        0.0020836263
72. ## number.vmail.messages             0.0194959757        0.0055413838
73. ## total.day.minutes                -0.0107600217        0.0117986600
74. ## total.day.calls                  -0.0006952217        0.0028044650
75. ## total.day.charge                 -0.0107568931        0.0118014339
76. ## total.eve.minutes                 0.9999997749       -0.0166391160
77. ## total.eve.calls                   0.0027780971        0.0017814106
78. ## total.eve.charge                  1.0000000000       -0.0166489191
79. ## total.night.minutes              -0.0166489191        1.0000000000
80. ## total.night.calls                 0.0134220174        0.0269718182
81. ## total.night.charge               -0.0166518367        0.9999992072
82. ## total.intl.minutes                0.0001320238       -0.0067209669
83. ## total.intl.calls                  0.0083930603       -0.0172140162
84. ## total.intl.charge                 0.0001547783       -0.0066545873
85. ## number.customer.service.calls    -0.0138363623       -0.0085325365


如果把高相关性的变量保存下来,可能会造成多重共线性问题,因此需要把高相关关系的变量删去。

Data Manipulation

从结果中可以看到,total.day.calls和total.day.charge之间存在一定的相关关系。
特别是voicemial为no的变量之间存在负相关关系。

 

Discretize (make categorical) a relevant numeric variable  

 

 

 

对变量进行离散化

 

construct a distribution of the variable with a churn overlay

construct a histogram of the variable with a churn overlay

 

 

Find a pair of numeric variables which are interesting with respect to churn.

从结果中可以看到,total.day.calls和total.day.charge之间存在一定的相关关系。

Model Building

特别是churn为no的变量之间存在相关关系。

 

1. ##                                 Estimate Std. Error t value Pr(>|t|)
2. ## (Intercept)                    0.3082150  0.0735760   4.189 2.85e-05 ***
3. ## stateAL                        0.0151188  0.0462343   0.327 0.743680
4. ## stateAR                        0.0894792  0.0490897   1.823 0.068399 .
5. ## stateAZ                        0.0329566  0.0494195   0.667 0.504883
6. ## stateCA                        0.1951511  0.0567439   3.439 0.000588 ***
7. ## international.plan yes         0.3059341  0.0151677  20.170  < 2e-16 ***
8. ## voice.mail.plan yes           -0.1375056  0.0337533  -4.074 4.70e-05 ***
9. ## number.vmail.messages          0.0017068  0.0010988   1.553 0.120402
10. ## total.day.minutes              0.3796323  0.2629027   1.444 0.148802
11. ## total.day.calls                0.0002191  0.0002235   0.981 0.326781
12. ## total.day.charge              -2.2207671  1.5464583  -1.436 0.151056
13. ## total.eve.minutes              0.0288233  0.1307496   0.220 0.825533
14. ## total.eve.calls               -0.0001585  0.0002238  -0.708 0.478915
15. ## total.eve.charge              -0.3316041  1.5382391  -0.216 0.829329
16. ## total.night.minutes            0.0083224  0.0695916   0.120 0.904814
17. ## total.night.calls             -0.0001824  0.0002225  -0.820 0.412290
18. ## total.night.charge            -0.1760782  1.5464674  -0.114 0.909355
19. ## total.intl.minutes            -0.0104679  0.4192270  -0.025 0.980080
20. ## total.intl.calls              -0.0063448  0.0018062  -3.513 0.000447 ***
21. ## total.intl.charge              0.0676460  1.5528267   0.044 0.965254
22. ## number.customer.service.calls  0.0566474  0.0033945  16.688  < 2e-16 ***
23. ## total.day.minutes1medium       0.0502681  0.0160228   3.137 0.001715 **
24. ## total.day.minutes1short        0.2404020  0.0322293   7.459 1.02e-13 ***

 

从结果中看,我们可以发现 state  total.intl.calls   、number.customer.service.calls 、 total.day.minutes1medium 、    total.day.minutes1short    的变量有重要的影响。

Use K-Nearest-Neighbors (K-NN) algorithm to develop a model for predicting Churn

1. ##         Direction.2005
2. ## knn.pred   1   2
3. ##        1 760  97
4. ##        2 100  43
5. 
6. 
7. [1] 0.803


混淆矩阵(英语:confusion matrix)是可视化工具,特别用于监督学习,在无监督学习一般叫做匹配矩阵。矩阵的每一列代表一个类的实例预测,而每一行表示一个实际的类的实例。
1. ##         Direction.2005
2. ## knn.pred   1   2
3. ##        1 827 104
4. ##        2  33  36
5. 
6. 
7. 
8. [1] 0.863

 

从测试集的结果,我们可以看到准确度达到86%。

 

Findings  

 

我们可以发现 ,total.day.calls和total.day.charge之间存在一定的相关关系。特别是churn为no的变量之间存在相关关系。同时我们可以发现 state  total.intl.calls   、number.customer.service.calls 、 total.day.minutes1medium、    total.day.minutes1short    的变量有重要的影响。同时我们可以发现,total.day.calls和total.day.charge之间存在一定的相关关系。最后从knn模型结果中,我们可以发现从训练集的结果中,我们可以看到准确度有80%,从测试集的结果,我们可以看到准确度达到86%。说明模型有很好的预测效果。

相关文章
|
1月前
|
存储 监控 算法
基于 C++ 哈希表算法实现局域网监控电脑屏幕的数据加速机制研究
企业网络安全与办公管理需求日益复杂的学术语境下,局域网监控电脑屏幕作为保障信息安全、规范员工操作的重要手段,已然成为网络安全领域的关键研究对象。其作用类似网络空间中的 “电子眼”,实时捕获每台电脑屏幕上的操作动态。然而,面对海量监控数据,实现高效数据存储与快速检索,已成为提升监控系统性能的核心挑战。本文聚焦于 C++ 语言中的哈希表算法,深入探究其如何成为局域网监控电脑屏幕数据处理的 “加速引擎”,并通过详尽的代码示例,展现其强大功能与应用价值。
48 1
|
26天前
|
人工智能 自然语言处理 算法
算法及模型合规:刻不容缓的企业行动指南
随着AI技术迅猛发展,算法与模型成为企业数字化转型的核心。然而,国家密集出台多项法规,如《人工智能生成合成内容标识办法》等,并开展“清朗·整治AI技术滥用”专项行动,标志着AI监管进入严格阶段。算法备案从“可选项”变为“必选项”,未合规可能面临罚款甚至刑事责任。同时,多地提供备案奖励政策,合规既是规避风险的需要,也是把握政策红利和市场信任的机遇。企业需系统规划合规工作,从被动应对转向主动引领,以适应AI时代的挑战与机遇。
|
2月前
|
机器学习/深度学习 存储 算法
18个常用的强化学习算法整理:从基础方法到高级模型的理论技术与代码实现
本文系统讲解从基本强化学习方法到高级技术(如PPO、A3C、PlaNet等)的实现原理与编码过程,旨在通过理论结合代码的方式,构建对强化学习算法的全面理解。
133 10
18个常用的强化学习算法整理:从基础方法到高级模型的理论技术与代码实现
|
2月前
|
数据采集 机器学习/深度学习 算法
别急着上算法,咱先把数据整明白:大数据分析的5个基本步骤,你都搞对了吗?
别急着上算法,咱先把数据整明白:大数据分析的5个基本步骤,你都搞对了吗?
89 4
|
2月前
|
存储 监控 算法
员工行为监控软件中的 Go 语言哈希表算法:理论、实现与分析
当代企业管理体系中,员工行为监控软件已逐步成为维护企业信息安全、提升工作效能的关键工具。这类软件能够实时记录员工操作行为,为企业管理者提供数据驱动的决策依据。其核心支撑技术在于数据结构与算法的精妙运用。本文聚焦于 Go 语言中的哈希表算法,深入探究其在员工行为监控软件中的应用逻辑与实现机制。
82 14
|
3月前
|
自然语言处理 算法 安全
境内深度合成服务算法备案通过名单分析报告
本报告基于《境内深度合成服务算法备案通过名单》,分析了2023年6月至2025年3月公布的10批备案数据,涵盖属地分布、行业应用及产品形式等多个维度。报告显示,深度合成算法主要集中于经济发达地区,如北京、广东、上海等地,涉及教育、医疗、金融、娱乐等多行业。未来趋势显示技术将向多模态融合、行业定制化和安全合规方向发展。建议企业加强技术研发、拓展应用场景、关注政策动态,以在深度合成领域抢占先机。此分析旨在为企业提供参考,助力把握技术发展机遇。
境内深度合成服务算法备案通过名单分析报告
|
3月前
|
供应链 算法 搜索推荐
从公布的前十一批其他算法备案通过名单分析
2025年3月12日,国家网信办发布算法备案信息,深度合成算法通过395款,其他算法45款。前10次备案中,深度合成算法累计3234款,其他类别647款。个性化推送类占比49%,涵盖电商、资讯、视频推荐;检索过滤类占31.53%,用于搜索优化和内容安全;调度决策类占9.12%,集中在物流配送等;排序精选类占8.81%,生成合成类占1.55%。应用领域包括电商、社交媒体、物流、金融、医疗等,互联网科技企业主导,技术向垂直行业渗透,内容安全和多模态技术成新增长点。未来大模型检索和多模态生成或成重点。
从公布的前十一批其他算法备案通过名单分析
|
3月前
|
机器学习/深度学习 人工智能 自然语言处理
AI训练师入行指南(三):机器学习算法和模型架构选择
从淘金到雕琢,将原始数据炼成智能珠宝!本文带您走进数字珠宝工坊,用算法工具打磨数据金砂。从基础的经典算法到精密的深度学习模型,结合电商、医疗、金融等场景实战,手把手教您选择合适工具,打造价值连城的智能应用。掌握AutoML改装套件与模型蒸馏术,让复杂问题迎刃而解。握紧算法刻刀,为数字世界雕刻文明!
126 6
|
3月前
|
人工智能 编解码 算法
如何在Python下实现摄像头|屏幕|AI视觉算法数据的RTMP直播推送
本文详细讲解了在Python环境下使用大牛直播SDK实现RTMP推流的过程。从技术背景到代码实现,涵盖Python生态优势、AI视觉算法应用、RTMP稳定性及跨平台支持等内容。通过丰富功能如音频编码、视频编码、实时预览等,结合实际代码示例,为开发者提供完整指南。同时探讨C接口转换Python时的注意事项,包括数据类型映射、内存管理、回调函数等关键点。最终总结Python在RTMP推流与AI视觉算法结合中的重要性与前景,为行业应用带来便利与革新。
160 5
|
3月前
|
人工智能 自然语言处理 供应链
从第十批算法备案通过名单中分析算法的属地占比、行业及应用情况
2025年3月12日,国家网信办公布第十批深度合成算法通过名单,共395款。主要分布在广东、北京、上海、浙江等地,占比超80%,涵盖智能对话、图像生成、文本生成等多行业。典型应用包括医疗、教育、金融等领域,如觅健医疗内容生成算法、匠邦AI智能生成合成算法等。服务角色以面向用户为主,技术趋势为多模态融合与垂直领域专业化。
下一篇
oss创建bucket