机器学习之逻辑回归

复制代码
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))
相关推荐
硅谷秋水1 小时前
Gemini Robotics 1.5 将 AI 智能体引入物理世界
人工智能·机器学习·语言模型·机器人
电科_银尘4 小时前
【大模型算法与工程 65】小数据VLM微调:图文格式、任务与损失
深度学习·算法·机器学习
絲唸5 小时前
可信机器学习与对抗鲁棒性:温度读数有误差,温室的高温判定还能信吗?
人工智能·python·深度学习·神经网络·算法·机器学习·机器人
在所不辞兄6 小时前
为什么电池老化成本需分段线性化嵌入调度?
人工智能·神经网络·机器学习·汽车
Regulus-Moon11 小时前
凸优化:局部即全局的定价表——条件数 κ 上的速率谱系
算法·机器学习·数学建模
专注仿真1 天前
仿真智能体训练(评估指标篇):任务完成率算法详解与实战
人工智能·算法·机器学习·afsim智能体·仿真训练·afsim智能体训练·任务完成率算法
高洁011 天前
高质量数据集的时效性:数据也会过期
人工智能·python·深度学习·机器学习·transformer
有Li1 天前
医疗大模型从刷榜走向临床试验|从组织病理学预测细胞生态位的肿瘤空间图谱平台文献速递
大数据·人工智能·学习·机器学习·医学生
Lucky高1 天前
大模型世界概述
深度学习·机器学习·ai