机器学习之逻辑回归

复制代码
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))
相关推荐
哥布林学者17 小时前
深度学习进阶(三十一)FlashAttention:IO 感知的精确注意力
机器学习·ai
通信小呆呆3 天前
当算法有了“五感”:多模态数据融合如何向人体感官协同学习?
人工智能·学习·算法·机器学习·机器人
xiao5kou4chang6kai43 天前
MATLAB机器学习、深度学习--从数据预处理到模型训练
深度学习·机器学习·matlab·数据预处理
code_pgf3 天前
端到端自动驾驶 BEV stack
人工智能·机器学习·自动驾驶
Godspeed Zhao3 天前
Level 4自动驾驶系统设计3——功能与场景3
人工智能·机器学习·自动驾驶
H178535090963 天前
SolidWorks第四部分_直接实体建模特征9_替换面原理
线性代数·算法·机器学习·3d建模·solidworks
Godspeed Zhao3 天前
现代智能汽车系统——智驾SoC之框架版图
人工智能·机器学习·自动驾驶·汽车·soc
指掀涛澜天下惊3 天前
AI 基础知识十九 强化学习前言
人工智能·机器学习·强化学习
大模型最新论文速读3 天前
06-16 · LLM 最新论文速览
论文阅读·人工智能·深度学习·机器学习·自然语言处理