机器学习之逻辑回归

复制代码
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))
相关推荐
KYGALYX9 分钟前
逻辑回归详解
算法·机器学习·逻辑回归
啵啵鱼爱吃小猫咪43 分钟前
机械臂能量分析
线性代数·机器学习·概率论
Σίσυφος19002 小时前
PCL 姿态估计 RANSAC + SVD(基于特征匹配)
人工智能·机器学习
Warren2Lynch2 小时前
C4 vs UML:从入门到结合使用的完整指南(含 Visual Paradigm AI 实操)
人工智能·机器学习·uml
小陈phd2 小时前
多模态大模型学习笔记(一)——机器学习入门:监督/无监督学习核心任务全解析
笔记·学习·机器学习
holeer2 小时前
【V2.0】王万良《人工智能导论》笔记|《人工智能及其应用》课程教材笔记
神经网络·机器学习·ai·cnn·nlp·知识图谱·智能计算
小陈phd2 小时前
多模态大模型学习笔记(二)——机器学习十大经典算法:一张表看懂分类 / 回归 / 聚类 / 降维
学习·算法·机器学习
算法狗23 小时前
大模型面试题:在混合精度训练中如何选择合适的精度
人工智能·深度学习·机器学习·语言模型
DuHz3 小时前
通过超宽带信号估计位置——论文精读
论文阅读·人工智能·机器学习·自动驾驶·汽车
Physicist in Geophy.3 小时前
一维波动方程(从变分法角度)
线性代数·算法·机器学习