机器学习_使用逻辑回归进行良/恶性乳腺癌肿瘤预测(附数据集下载链接, 长期有效)

关于代码中导入的模块, 个人更建议把导入的各个模块放在代码最前面, 有利于后期封装函数

当然, 对于新手来说, 我的建议是模块在使用的时候导入, 这样学习的印象更深刻,

等到知识和代码都熟练了, 再改也不迟

python 复制代码
# 1.导入外部数据集breast-cancer-wisconsin
import pandas as pd
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"]
cancer_data=pd.read_csv(r"C:\Users\鹰\Desktop\ML_Set\breast_cancer_wisconsin\breast-cancer-wisconsin.data", names=names)
# 2.数据基本处理- 缺失值处理, 确定特征值和目标值, 数据集分割
# 缺失值处理, 关于缺失值, 特殊字符和异常值的检测和处理,  教学视频内没有讲, 怎么搞?
import numpy as np
print(cancer_data.isna().sum())
cancer_data=cancer_data.replace(to_replace="?", value=np.nan)
cancer_data=cancer_data.dropna()
# 确定特征值, 目标值
x_all=cancer_data.iloc[:, 1:-1]
y_all=cancer_data.iloc[:,-1]
# 分割数据集
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x_all,y_all, test_size=0.2)
# 3.特征工程-特征预处理
# 特征预处理-标准化
from sklearn.preprocessing import StandardScaler
scaler=StandardScaler()
scaler.fit_transform(x_train)
scaler.fit_transform(x_test)
# 4.模型训练-逻辑回归
from sklearn.linear_model import LogisticRegression
estimator=LogisticRegression()
estimator.fit(x_train,y_train)
# 5.模型评估-预测值, 准确率, 分类模型的评估指标[精确率, 召回率, f1-score, AUC]
# 预测值
y_predict=estimator.predict(x_test)
print("predict_values :", y_predict)
# 准确率
score=estimator.score(x_test, y_test)
print("accuracy :", score)

# 精确率, 召回率, f1-score
from sklearn.metrics import classification_report
class_report=classification_report(y_test, y_predict,labels=(2,4),target_names=("Benign tumor(良性肿瘤)", "Malignant tumor(恶性肿瘤)"))
print(class_report)

# AUC指标, 适合评估不平衡二分类问题
y_test=np.where(y_test>3,1,0)
from sklearn.metrics import roc_auc_score
AUC=roc_auc_score(y_test,y_predict)
print("AUC :", AUC)

为了防止失效, 我就多放几个地址, 理解万岁,

第一个直接去官网下载数据集, 第二个是我通过百度网盘分享的链接

地址1:

Breast Cancer Wisconsin (Original) - UCI Machine Learning Repositoryhttps://archive.ics.uci.edu/dataset/15/breast+cancer+wisconsin+original

兄弟们, 注意啊,刻骨铭心的教训 当进入UCI网站时, 收索乳腺癌肿瘤预测, 会查找到三个数据集, 咱们应该选择数据集后面标注original, 样本数量为699的数据集

地址2:

链接:https://pan.baidu.com/s/1sTJdDaj_pXUvurlCWzWFDQ

提取码:dzlk

今天作者无话可说, 咱们青山不改, 有缘再见

相关推荐
985小水博一枚呀10 分钟前
【AI大模型学习路线】第二阶段之RAG基础与架构——第七章(【项目实战】基于RAG的PDF文档助手)技术方案与架构设计?
人工智能·学习·语言模型·架构·大模型
pystraf10 分钟前
LG P9844 [ICPC 2021 Nanjing R] Paimon Segment Tree Solution
数据结构·c++·算法·线段树·洛谷
白熊18824 分钟前
【图像生成大模型】Wan2.1:下一代开源大规模视频生成模型
人工智能·计算机视觉·开源·文生图·音视频
weixin_5145488929 分钟前
一种开源的高斯泼溅实现库——gsplat: An Open-Source Library for Gaussian Splatting
人工智能·计算机视觉·3d
掘金-我是哪吒1 小时前
分布式微服务系统架构第132集:Python大模型,fastapi项目-Jeskson文档-微服务分布式系统架构
分布式·python·微服务·架构·系统架构
四口鲸鱼爱吃盐1 小时前
BMVC2023 | 多样化高层特征以提升对抗迁移性
人工智能·深度学习·cnn·vit·对抗攻击·迁移攻击
飞川撸码1 小时前
【LeetCode 热题100】739:每日温度(详细解析)(Go语言版)
算法·leetcode·golang
yuhao__z1 小时前
代码随想录算法训练营第六十六天| 图论11—卡码网97. 小明逛公园,127. 骑士的攻击
算法
Echo``1 小时前
3:OpenCV—视频播放
图像处理·人工智能·opencv·算法·机器学习·视觉检测·音视频
Douglassssssss1 小时前
【深度学习】使用块的网络(VGG)
网络·人工智能·深度学习