机器学习之逻辑回归

复制代码
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))
相关推荐
AI小云3 天前
【机器学习与实战】回归分析与预测:线性回归-03-损失函数与梯度下降
机器学习
L.fountain3 天前
机器学习shap分析案例
人工智能·机器学习
weixin_429630263 天前
机器学习-第一章
人工智能·机器学习
Cedric11133 天前
机器学习中的距离总结
人工智能·机器学习
寒月霜华3 天前
机器学习-数据标注
人工智能·机器学习
Godspeed Zhao3 天前
自动驾驶中的传感器技术46——Radar(7)
人工智能·机器学习·自动驾驶
limengshi1383923 天前
机器学习面试:请介绍几种常用的学习率衰减方式
人工智能·学习·机器学习
救救孩子把3 天前
2-机器学习与大模型开发数学教程-第0章 预备知识-0-2 数列与级数(收敛性、幂级数)
人工智能·数学·机器学习
蒋星熠3 天前
如何在Anaconda中配置你的CUDA & Pytorch & cuNN环境(2025最新教程)
开发语言·人工智能·pytorch·python·深度学习·机器学习·ai
Hcoco_me4 天前
什么是机器学习?
人工智能·机器学习