当前位置: 首页 > news >正文

决策树项目——电信客户流失预测

AUC性能测量

在机器学习中,性能测量是一项基本任务。因此,当涉及到分类问题时,我们可以依靠AUC - ROC曲线。当我们需要检查或可视化多类分类问题的性能时,我们使用AUC(曲线下面积)ROC(接收器工作特性)曲线。它是检查任何分类模型性能的最重要评估指标之一。

AUC的含义

AUC是衡量学习器优劣的一种性能指标。从定义可知,AUC可通过对ROC曲线下各部分的面积求和而得。AUC越大,说明模型对正负样本的区分能力越强,模型的性能也就越好。

AUC的优点

AUC考虑了分类器对于正例和负例的分类能力,在样本不平衡的情况下,依然能够对分类器作出合理的评价。它不受样本不平衡问题的影响,因此是一个相对稳健的评价指标。

项目案例:

import pandas as pd # 可视化混淆矩阵 def cm_plot(y, yp): from sklearn.metrics import confusion_matrix import matplotlib.pyplot as plt cm = confusion_matrix(y, yp) plt.matshow(cm, cmap=plt.cm.Blues) plt.colorbar() for x in range(len(cm)): for y in range(len(cm)): plt.annotate(cm[x, y], xy=(y, x), horizontalalignment='center', verticalalignment='center') plt.ylabel('True label') plt.xlabel('Predicted label') return plt # 导入数据 datas = pd.read_excel(r"E:\xwechat_files\wxid_qi43v1w2nqcb12_e432\msg\file\2025-12\电信客户流失数据.xlsx") # 将变量与结果划分开 data = datas.iloc[:, :-1] # 1、datas.年龄 datas[年龄] datas.iloc[ : , :-1] target = datas.iloc[:, -1] # # 划分数据集 """ 导入模块对数据进行划分; """ from sklearn.model_selection import train_test_split data_train, data_test, target_train, target_test = \ train_test_split(data, target, test_size=0.2, random_state=42) # 定义决策树 from sklearn import tree dtr = tree.DecisionTreeClassifier(criterion='gini', max_depth=8, random_state=60) dtr.fit(data_train, target_train) """ 训练集混淆矩阵 """ # 训练集预测值 train_predicted = dtr.predict(data_train) from sklearn import metrics # 绘制混淆矩阵 print(metrics.classification_report(target_train, train_predicted)) # 可视化混淆矩阵 cm_plot(target_train, train_predicted).show() """ 测试集混淆矩阵 """ # 测试集预测值 test_predicted = dtr.predict(data_test) # 直接得到预测的结果 # 绘制混淆矩阵 print(metrics.classification_report(target_test, test_predicted)) # 可视化混淆矩阵 cm_plot(target_test, test_predicted).show() # 对决策树测试集进行评分 dtr.score(data_test, target_test) '''AUC值的计算''' y_pred_proba = dtr.predict_proba(data_test) a = y_pred_proba[:, 1] auc_result = metrics.roc_auc_score(target_test, a) '''绘制AUC-ROC曲线''' import matplotlib.pyplot as plt from sklearn.metrics import roc_curve # 得到不同阈值的roc # 计算ROC曲线的点 fpr, tpr, thresholds = roc_curve(target_test, a) # 用来计算不同阈值下的fpr和tpr, # 绘制ROC曲线 plt.figure() plt.plot(fpr, tpr, color='darkorange', lw=2, label='ROC curve(area=%0.2f)' % auc_result) plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle='--') # 函数来绘制一条从点 (0,0) 到点 (1,1) 的线段。 plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('Receiver Operating Characteristic') plt.legend() plt.show() # 到逻辑回归里

http://www.jsqmd.com/news/121235/

相关文章:

  • GraniStudio : MC 协议深度剖析
  • 1、Windows 10入门指南:开启便捷数字生活
  • Qwen3-235B双模式推理大模型发布:重新定义智能交互的效率与深度
  • Excalidraw商标使用规范:品牌保护边界
  • 2、Windows 10 电脑操作与应用使用全指南
  • Excalidraw水印功能添加建议:防止截图外泄
  • ASM1042型CANFD接口芯片的主要特性及多节点连接方式解析
  • Excalidraw审计日志功能设计:操作追溯需求
  • 3、Windows 10 使用与设置指南
  • Excalidraw备份恢复机制设计原则与实施步骤
  • Excalidraw图形序列化格式分析:JSON结构详解
  • Qwen3-235B:单模型双模式推理新突破
  • Excalidraw构建流程剖析:前端打包优化空间
  • LongCat-Video:分钟级长视频高效生成模型
  • 腾讯开源SongGeneration:LeVo架构高品质AI作曲
  • Excalidraw缩放和平移功能技术实现细节
  • 4、Windows 10 使用指南:系统设置、网络连接与账户创建
  • Windows 10版本
  • 基于SpringBoot+Vue的软件缺陷跟踪管理系统设计与实现
  • 5、Windows 10 账户管理与桌面使用全攻略
  • Nitro-E:304M参数极速图文扩散模型
  • MySQL的安装与卸载
  • Excalidraw能否用于游戏关卡设计原型绘制?
  • 6、Windows 10 使用指南与网页浏览基础
  • Qwen-Image-Edit-MeiTu:DiT赋能图像编辑新高度
  • java高校创新创业项目管理系统springboot-vue
  • Excalidraw企业合作案例:某银行内部部署实例
  • Kimi Linear:1M tokens下6倍解码效率的线性模型
  • PCB布线——电源
  • 【Prisma】如何修复(重建)已经损坏的迁移历史?