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

机器学习实现逻辑回归-癌症分类预测

1.数据来源

https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data

2.代码示例(已添加注释)

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression,Ridge
from sklearn.metrics import classification_report,roc_auc_score
#给列名字
names = ['Sample code number', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape','Marginal Adhesion', 'Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin','Normal Nucleoli', 'Mitoses', 'Class']data = pd.read_csv('https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data',names = names)##数据预处理:去除以?表示的缺失值
data.replace('?',np.nan,inplace=True)
data.dropna(inplace=True)##目标值和特征值
tezheng=data.iloc[:,1:10]
mubiao=data['Class']##划分数据
x_train,x_test,y_train,y_test=train_test_split(tezheng,mubiao,random_state=22)##特征工程:标准化
trans=StandardScaler()
x_train=trans.fit_transform(x_train)
x_test=trans.transform(x_test)##生成模型
em = LogisticRegression(solver='sag')
em.fit(x_train,y_train)
y_pre=em.predict(x_test)
print(em.coef_,em.intercept_)
print(em.score(x_test,y_test))##模型评估
print(y_test==y_pre)
report=classification_report(y_test,y_pre,labels=[2,4],target_names=['良性','恶性'])##求解准确率与召回率
print(report)
y_test1=np.where(y_test>3,1,0)##roc_auc函数的第一个参数要求必须是1,0分类才行,且1表示正例
print(roc_auc_score(y_test1,y_pre))##计算AUC指标,确定模型是否受样本不均衡影响,越接近1,越好,越接近0.5越差
##注意精确率,召回率,ROC_AUC指标是评估二分类的模型性能的指标

http://www.dtcms.com/a/568548.html

相关文章:

  • Kafka 从入门到精通完整指南
  • 常见二三维GIS数据分类及处理流程图
  • LLM结构化输出:约束解码、CFG和response_format
  • 做网站麻烦不文山网站建设求职简历
  • wordpress网站静态页面外国食品优秀设计网站
  • hybrid
  • C++中malloc、free和new、delete的区别
  • 计算机视觉:python车辆行人检测与跟踪系统 YOLO模型 SORT算法 PyQt5界面 目标检测+目标跟踪 深度学习 计算机✅
  • 提高肠氧饱和度测量精度的新技术评估
  • 【数据集+源码+文章】基于yolov8+streamlit的12种水果品质、成熟度检测系统
  • Camera参数(3A)
  • 【C++:搜索二叉树】二叉搜索树从理论到实战完全解读:原理、两种场景下的实现
  • 高性能网络编程实战:用Tokio构建自定义协议服务器
  • H265 vs AV1 vs H266帧内块拷贝差异
  • CSS 中 `data-status` 的使用详解
  • 舟山企业网站建设公司微信小程序麻将辅助免费
  • VMware替代 | 详解ZStack ZSphere产品化运维六大特性
  • 缓存击穿,缓存穿透,缓存雪崩的原因和解决方案(或者说使用缓存的过程中有没有遇到什么问题,怎么解决的)
  • 关于数据包分片总长度字段的计算和MF标志位的判断
  • 手机网站建站流程网站建设卩金手指科杰
  • BuildingAI 用户信息弹出页面PRD
  • ​Oracle RAC灾备环境UNDO表空间管理终极指南:解决备库修改难题与性能优化实战​
  • 《uni-app跨平台开发完全指南》- 02 - 项目结构与配置文件详解
  • 【数据分析】基于R语言的废水微生物抗性分析与负二项回归模型建模
  • 深圳专业网站公司注册查询网站
  • k8s --- resource 资源
  • 神经网络之反射变换
  • k8s——pod详解2
  • 四层神经网络案例(含反向传播)
  • MySQL初阶学习日记(1)--- 数据库的基本操作