癌症分类预测-良/恶性乳腺癌肿瘤预测

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

#ssl报错的话就导入
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
1.获取数据
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.head()

上述代码可以直接导入先看看结果,因为列名不对 所以才用names指定列名

2.基本数据处理
2.1 缺失值处理
data = data.replace(to_replace="?", value=np.NaN)
data = data.dropna()
2.2 确定特征值,目标值
x = data.iloc[:, 1:10]
x.head()
y = data["Class"]
y.head()
2.3 分割数据
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=22)

data.ioc[:,1:10] 解释

:表示所有行

1:10 表示1到10列

3.特征工程(标准化)
transfer = StandardScaler()
x_train = transfer.fit_transform(x_train)
x_test = transfer.transform(x_test)

以上是对数据进行标准化处理

4.机器学习(逻辑回归)
estimator = LogisticRegression()
estimator.fit(x_train, y_train)

采用逻辑回归 将训练数据 和 训练的目标值y 传进去

自动出结果

5.模型评估
y_predict = estimator.predict(x_test)
y_predict
estimator.score(x_test, y_test)

用测试数据苹果预测结果!

Original: https://blog.csdn.net/weixin_44199723/article/details/126508227
Author: H A I
Title: 癌症分类预测-良/恶性乳腺癌肿瘤预测

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/665222/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球