机器学习之逻辑回归

复制代码
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))
相关推荐
宝贝儿好几秒前
【LLM】第四章:项目实操案例:文本情感分析
人工智能·深度学习·神经网络·机器学习·自然语言处理·lstm
数智工坊1 小时前
周志华《Machine Learning》学习笔记--第九章--聚类
笔记·学习·机器学习
专注搞钱1 小时前
半导体MES智能化升级方案:基于机器学习与Transformer大模型落地实战手册
人工智能·机器学习·transformer
Eloudy1 小时前
光子的单缝衍射模型
线性代数·机器学习·概率论
dd0121 小时前
从标签平滑到不确定性建模:SoftLabel如何重塑机器认知边界
机器学习·医疗影像诊断·不确定性建模·softlabel
weixin_4296302610 小时前
3.49 HVLF:一种跨场景的整体视觉定位框架
深度学习·机器学习·计算机视觉
深圳市机智人激光雷达10 小时前
技术筑牢安全冗余:激光雷达在自动驾驶高阶感知中的底层价值与范式演进
人工智能·安全·机器学习·3d·机器人·自动驾驶·无人机
DreamLife☼14 小时前
OpenBCI-实战五:脑电数据可视化仪表板
人工智能·机器学习·信息可视化·开源硬件·脑机接口·openbci
行业研究员16 小时前
腾讯云AgentMemory产品介绍与核心痛点解决
人工智能·机器学习·腾讯云·agentmem
苏州邦恩精密17 小时前
江苏蔡司3D扫描仪定制厂家:专业三维检测方案助力智能制造升级
人工智能·科技·机器学习·3d·自动化·制造