机器学习之逻辑回归

复制代码
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))
相关推荐
liruiqiang051 小时前
机器学习 - 衡量模型的特性
人工智能·机器学习
西猫雷婶2 小时前
python学智能算法(三)|模拟退火算法:深层分析
算法·机器学习·模拟退火算法
香橙薄荷心2 小时前
人工智能之自动驾驶技术体系
人工智能·机器学习·自动驾驶
星霜旅人4 小时前
开源机器学习框架
人工智能·机器学习·开源
龚大龙4 小时前
机器学习(李宏毅)——RL(强化学习)
人工智能·机器学习
万事可爱^11 小时前
HDBSCAN:密度自适应的层次聚类算法解析与实践
算法·机器学习·数据挖掘·聚类·hdbscan
若兰幽竹15 小时前
【机器学习】多元线性回归算法和正规方程解求解
算法·机器学习·线性回归
Watermelo61715 小时前
从DeepSeek大爆发看AI革命困局:大模型如何突破算力囚笼与信任危机?
人工智能·深度学习·神经网络·机器学习·ai·语言模型·自然语言处理
北_鱼16 小时前
支持向量机(SVM):算法讲解与原理推导
算法·机器学习·支持向量机
IT古董20 小时前
【漫话机器学习系列】100.L2 范数(L2 Norm,欧几里得范数)
人工智能·机器学习