当前位置:网站首页>良/恶性乳腺肿瘤预测(逻辑回归分类器)
良/恶性乳腺肿瘤预测(逻辑回归分类器)
2022-06-27 20:49:00 【别团等shy哥发育】
乳腺肿瘤预测
案例:良/恶性乳腺肿瘤预测
1.1 简介
本案例使用逻辑回归分类器对乳腺肿瘤进行良性/恶性预测,并对预测模型进行指标测算与评价。
这里数据集采用乳腺癌数据集,原始的数据集下载地址为:https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data。
数据特征如下:

1.2 代码
将每个属性的特征量化为1~10的数值进行表示。首先,导入数据并显示前5条数据。
1.2.1 导入数据集
import pandas as pd
import numpy as np
column_names=['number','Cl_Thickness','Unif_cell_size','Unif_cell_shape','Marg_Adhesion','Sing_epith_cell_size','Bare_nuclei','Bland_chromation','Norm_nuclei','Mitoses','Class']
data=pd.read_csv('breast-cancer-wisconsin.data',names=column_names)
display(data.head())

1.2.2 浏览数据的基本信息
data.info()

1.2.3 查看数据的基本统计信息
data.describe()

1.2.4 统计数据属性中的缺失值
data.isnull().sum()

如果存在缺失数据,需要丢弃或填充。该数据集中并没有缺失值。这里我们采取删除缺失值的方法
data=data.replace(to_replace='?',value=np.nan)
data=data.dropna(how='any')
print(data.shape)

1.2.5 将数据集划分为训练集和测试集
from sklearn.model_selection import train_test_split
# 划分训练集与测试集
X_train,X_test,y_train,y_test=train_test_split(data[column_names[1:10]],data[column_names[10]],test_size=0.25,random_state=33)
print('训练样本的数量和类别分布:\n',y_train.value_counts())

1.2.6 标准化数据
每个维度的特征数据方差为1,均值为0,使得预测结果不会被某些维度过大的特征值主导。
from sklearn.preprocessing import StandardScaler
ss=StandardScaler()
X_train=ss.fit_transform(X_train)
X_test=ss.transform(X_test)
print(X_train.mean())

1.2.7 分别用LogisticRegression与SGDClassifier构建分类器
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import SGDClassifier
lr=LogisticRegression()
sgdc=SGDClassifier()
lr.fit(X_train,y_train)
lr_y_predict=lr.predict(X_test)
sgdc.fit(X_train,y_train)
sgdc_y_predict=sgdc.predict(X_test)
1.2.8 分析LR分类器性能
from sklearn.metrics import classification_report
print('Accuracy of LR Classifier:',lr.score(X_test,y_test))
print(classification_report(y_test,lr_y_predict,target_names=['Benign','Malignant']))

1.2.9 SGD分类器性能分析
print('Accuracy of SGD Classifier:',sgdc.score(X_test,y_test))
print(classification_report(y_test,sgdc_y_predict,target_names=['Benign','Malignant']))
# print(classification_report(y_test,sgdc_y_predict))

precision 精确率
recall 召回率
f1_score F1值
macro avg 宏观平均值
weighted avg 加权平均值
边栏推荐
- 云辅助隐私集合求交(Server-Aided PSI)协议介绍:学习
- Detect objects and transfer images through mqtt
- PHP connects to database to realize user registration and login function
- 消除el-image图片周围间隙
- 新加坡国立大学|采用无模型强化学习方法评估能源效益数据中心的节能情况
- Arcgis-engine二次开发之空间关系查询与按图形查询
- 元气森林的5元有矿之死
- Summary of various loams (laser SLAM)
- Spark BUG实践(包含的BUG:ClassCastException;ConnectException;NoClassDefFoundError;RuntimeExceptio等。。。。)
- Discuz small fish game wind shadow legend business gbk+utf8 version template /dz game website template
猜你喜欢

量化交易入门教程

官宣!Apache Doris 从 Apache 孵化器毕业,正式成为 Apache 顶级项目!

Discuz taobaoke website template / Dean taobaoke shopping style commercial version template

云辅助隐私集合求交(Server-Aided PSI)协议介绍:学习

The most illusory richest man in China is even more illusory

PE买下一家内衣公司

雪糕还是雪“高”?

网易云“情怀”底牌失守

广告太「野」,吉野家「渡劫」

【IDEA】IDEA 格式化 代码技巧 idea 格式化 会加 <p> 标签
随机推荐
2022年第一季度“广州好人”刘磊峰:具有强烈的诚信意识和食品安全意识
Discuz淘宝客网站模板/迪恩淘宝客购物风格商业版模板
Zabbix6.0 upgrade Guide - how to synchronize database upgrades?
pytorch 入门指南
这届考生,报志愿比高考更“拼命”
实践torch.fx:基于Pytorch的模型优化量化神器
netERR_ CONNECTION_ Refused solution
跟着存档教程动手学RNAseq分析(二)
量化交易入门教程
【数字IC/FPGA】检测最后一个匹配序列的位置
Death of 5 yuan youkuang in Yuanqi forest
MapReduce初级编程实践
Working at home is more tiring than going to work at the company?
Livox lidar+ Hikvision camera real-time 3D reconstruction based on loam to generate RGB color point cloud
Detect objects and transfer images through mqtt
广告太「野」,吉野家「渡劫」
Is it safe to use flush mobile phones to speculate in stocks?
「R」使用ggpolar绘制生存关联网络图
医美大刀,砍向00后
树莓派(以及各种派)使用指南