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))
机器学习之逻辑回归
我叫小邋遢2023-08-19 22:53
相关推荐
AI大模型测试3 小时前
大龄程序员想转行到AI大模型,好转吗?金融小师妹5 小时前
基于LSTM-GARCH-EVT混合模型的贵金属极端波动解析:黄金白银双双反弹的逻辑验证LucDelton7 小时前
模型微调思路Fleshy数模8 小时前
从一条直线开始:线性回归的底层逻辑与实战流㶡8 小时前
逻辑回归实战:从原理到不平衡数据优化(含欠拟合/过拟合诊断与召回率提升)lrh1228009 小时前
详解决策树算法:分类任务核心原理、形成流程与剪枝优化冰西瓜6009 小时前
从项目入手机器学习(五)—— 机器学习尝试Coding茶水间9 小时前
基于深度学习的狗品种检测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)Fleshy数模10 小时前
从欠拟合到正则化:用逻辑回归破解信用卡失信检测的召回率困境jackywine610 小时前
零样本学习(Zero-Shot Learning)和少样本学习(Few-Shot Learning)有何区别?AI 是怎么“猜“出来的