机器学习之逻辑回归

复制代码
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))
相关推荐
猎头南楼4 天前
知识社区推荐系统实践:新用户冷启动与长短期兴趣建模的挑战 资深推荐算法工程师
人工智能·深度学习·算法·机器学习
高洁014 天前
未来三年,AI 落地的五个确定性判断一
人工智能·深度学习·机器学习·transformer·知识图谱
Omics Pro4 天前
斯坦福Nature+Science|广义虚拟细胞基础大模型
数据库·人工智能·算法·机器学习·自然语言处理
翰佰尔生物HiOmics云分析4 天前
老年COVID-19重症化风险预测机器学习在线工具技术解析
机器学习·开发·预测·covid-19
一只废狗狗狗狗狗狗狗狗狗4 天前
机器学习:分类问题及损失函数优化
机器学习
workflower4 天前
SSH(Struts+Spring+Hibernate)
人工智能·机器学习·机器人·云计算·无人机
陈年老古董4 天前
微博情感分析项目学习笔记
笔记·python·学习·机器学习·项目
isfox4 天前
为什么说线性模型是深度学习的基石?从 Scikit-Learn 谈起
机器学习
别动我齐刘海4 天前
ROS2 Jazzy + C++ 实战路线——ros2_control
c++·人工智能·python·opencv·机器学习·机器人·github
明志数科4 天前
机器人数据采集过程中五类异常片段的判定与处理
机器学习·机器人