import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
# 获得数据
names=['Sample code number','Clump Thickness','Uniformity of Cell Size','Uniformity of Cell Shape','Marginal Adhesion','Single Hpithelial Cell Size','Bare Nucle','Bland Chromatin','Normal Nucleoli','Mitomeos','Class']
data=pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",names=names)
# 处理数据 处理掉数据里的缺失值
data=data.replace(to_replace="?",value=np.nan)
# 使用dropna删除替代过的数据
data=data.dropna()
# 分类数据 特征值 标准值
x=data.iloc[:,1:-1]
y=data["Class"]
# 分割数据
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=20)
# 标准化数据
transfer =StandardScaler()
x_train=transfer.fit_transform(x_train)
x_test=transfer.fit_transform(x_test)
# 训练模型
estimator=LogisticRegression()
ret=estimator.fit(x_train,y_train)
print(ret)
# 模型评估
print(estimator.score(x_test,y_test))
机器学习之逻辑回归
我叫小邋遢2023-08-19 22:53
相关推荐
珠海西格电力1 天前
零碳园区管理系统的性能评估体系的行业标准Yolanda_20221 天前
如何开发人工智能系统:从专家系统到机器学习段一凡-华北理工大学1 天前
高炉炼铁机器视觉与智能识别十八讲~系列文章15:可靠性篇:防误报、容错与识别系统的鲁棒性设计jay神1 天前
基于 YOLOv8 的手势识别系统AI日报派送佬1 天前
2026年10月22日AI行业日报|AI智能体正面开战、云厂商模型生态洗牌、算力基建加速落地,同时智能体安全、高危漏洞风险持续拉响警报ZKNOW甄知科技1 天前
燕千云迭代版本发布:智能Agent深入业务现场枫叶丹41 天前
表格数据也能用基础模型:TabPFN 与传统机器学习的比较方法Ivanqhz1 天前
超参数考量与设计硅谷秋水1 天前
VLMeg:把 VLM 从奖励回归器变成成功检测器jay神1 天前
基于 YOLOv8 的垃圾分类识别系统