机器学习之逻辑回归

复制代码
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))
相关推荐
2501_9269783316 分钟前
《与AI的妄想对话:如何给机器人造灵魂?》
人工智能·深度学习·机器学习·ai写作·agi
程序员Shawn18 分钟前
【机器学习 | 第三篇】- 线性回归
人工智能·机器学习·线性回归
Master_oid37 分钟前
机器学习36:机器学习概述
人工智能·机器学习
nancy_princess2 小时前
基础概念2
人工智能·python·机器学习
章鱼丸-2 小时前
DAY40 训练与测试规范写法
人工智能·算法·机器学习
沃达德软件2 小时前
5G技术推动移动视频监控
人工智能·深度学习·5g·目标检测·机器学习·计算机视觉
源码之家2 小时前
计算机毕业设计:基于Python与协同过滤的美食推荐系统 Django框架 可视化 协同过滤推荐算法 菜谱 食品 机器学习(建议收藏)✅
爬虫·python·机器学习·django·毕业设计·课程设计·美食
人工干智能3 小时前
科普:从交叉验证法的Out-of-Fold Prediction,到集成学习的Stacking
人工智能·机器学习·集成学习
凸头3 小时前
CRAG、Self-RAG、Adaptive RAG 经典论文总结概要
人工智能·深度学习·机器学习·rag
直有两条腿3 小时前
【机器学习】K-Means 算法
算法·机器学习·kmeans