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
相关推荐
OpenBayes贝式计算3 天前
解决视频模型痛点,TurboDiffusion 高效视频扩散生成系统;Google Streetview 涵盖多个国家的街景图像数据集OpenBayes贝式计算3 天前
OCR教程汇总丨DeepSeek/百度飞桨/华中科大等开源创新技术,实现OCR高精度、本地化部署够快云库3 天前
能源行业非结构化数据治理实战:从数据沼泽到智能资产B站_计算机毕业设计之家3 天前
电影知识图谱推荐问答系统 | Python Django系统 Neo4j MySQL Echarts 协同过滤 大数据 人工智能 毕业设计源码(建议收藏)✅Flying pigs~~4 天前
机器学习之逻辑回归Evand J4 天前
通过matlab实现机器学习的小项目示例(鸢尾花分类)_Li.4 天前
Simulink - 6DOF (Euler Angles)Project_Observer4 天前
工时日志在项目进度管理中扮演着怎样的角色?scott1985124 天前
Improving Classifier-Free Guidance of Flow Matching via Manifold Projection