恶性肿瘤预测Python程序(逻辑回归)
from sklearn.linear_model import LinearRegression,SGDRegressor,Ridge,LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_squared_error,classification_report
import numpy as np
import pandas as pd
def logistic():
column= ['Sample code number', 'Clump Thickness', 'Uniformity of Cell Size', 'Uniformity of Cell Shape',
'Marginal Adhesion','Single Epithelial Cell Size', 'Bare Nuclei', 'Bland Chromatin', 'Normal Nucleoli', 'Mitoses', 'Class']
data=pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/breast-cancer-wisconsin/breast-cancer-wisconsin.data",names=column)
print(data)
data=data.replace(to_replace='?',value=np.nan)#缺失值进行处理
data=data.dropna()
x_train,x_test,y_train,y_test=train_test_split(data[column[1:10]],data[column[10]],test_size=0.25)
#进行标准化处理
std=StandardScaler()
x_train=std.fit_transform(x_train)
x_test=std.transform(x_test)
lg = LogisticRegression(C=1.0)
lg.fit(x_train, y_train)
y_predict=lg.predict(x_test)
print(lg.coef_)
print("准确率",lg.score(x_test,y_test))
print("召回率",classification_report(y_test,y_predict,labels=[2,4],target_names=["良性","恶性"]))
return None
if __name__ =="__main__":
logistic()

恶性肿瘤预测Python程序(逻辑回归)的更多相关文章
- 机器学习_线性回归和逻辑回归_案例实战:Python实现逻辑回归与梯度下降策略_项目实战:使用逻辑回归判断信用卡欺诈检测
线性回归: 注:为偏置项,这一项的x的值假设为[1,1,1,1,1....] 注:为使似然函数越大,则需要最小二乘法函数越小越好 线性回归中为什么选用平方和作为误差函数?假设模型结果与测量值 误差满足 ...
- Python之逻辑回归模型来预测
建立一个逻辑回归模型来预测一个学生是否被录取. import numpy as np import pandas as pd import matplotlib.pyplot as plt impor ...
- 机器学习之使用Python完成逻辑回归
一.任务基础 我们将建立一个逻辑回归模型来预测一个学生是否被大学录取.假设你是一个大学系的管理员,你想根据两次考试的结果来决定每个申请人的录取机会.你有以前的申请人的历史数据,你可以用它作为逻辑回归的 ...
- 吴裕雄 python 机器学习——逻辑回归
import numpy as np import matplotlib.pyplot as plt from matplotlib import cm from mpl_toolkits.mplot ...
- python机器学习——逻辑回归
我们知道感知器算法对于不能完全线性分割的数据是无能为力的,在这一篇将会介绍另一种非常有效的二分类模型--逻辑回归.在分类任务中,它被广泛使用 逻辑回归是一个分类模型,在实现之前我们先介绍几个概念: 几 ...
- python机器学习-逻辑回归
1.逻辑函数 假设数据集有n个独立的特征,x1到xn为样本的n个特征.常规的回归算法的目标是拟合出一个多项式函数,使得预测值与真实值的误差最小: 而我们希望这样的f(x)能够具有很好的逻辑判断性质,最 ...
- python实现逻辑回归
首先得明确逻辑回归与线性回归不同,它是一种分类模型.而且是一种二分类模型. 首先我们需要知道sigmoid函数,其公式表达如下: 其函数曲线如下: sigmoid函数有什么性质呢? 1.关于(0,0. ...
- Python使用逻辑回归估算OR值
第一种是统计学方法,需要用到 statsmodels包 statsmodels是统计和计量经济学的package,包含了用于参数评估和统计测试的实用工具 第二种是机器学习,需要使用sklearn中的L ...
- 用python实现逻辑回归
机器学习课程的一个实验,整理出来共享. 原理很简单,优化方法是用的梯度下降.后面有测试结果. # coding=utf-8 from math import exp import matplotlib ...
随机推荐
- Android 8.0 新特性
Android 8.0 (Android Oreo(奥利奥))新特性介绍 通知渠道 - Notification Channels 通知渠道是由应用自行定义的通知内容类别,借助渠道,开发者可以让用户对 ...
- Flex NumberFormatter 数值的格式化
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- Memcache操作类
using Memcached.ClientLibrary; using System; using System.Collections.Generic; using System.Linq; us ...
- 使用子查询创建表(oracle)
转自:https://blog.csdn.net/lxh123456789asd/article/details/81164321 语句: CREATE TABLE tablename[(column ...
- java中线程池的使用
public static ExecutorSevice newSingleThreadExecutor() public static ExecutorSevice newFixedThreadPo ...
- 微信小程序request请求封装
var app = getApp(); function request(url,postData,doSuccess,doFail,doComplete){ var host = getApp(). ...
- Redis简单生产者消费者
注意:redis客户端执行是单线程的,不能将客户端放在外面,内部执行使用多线程的方式. // 创建生产端连接 final Jedis jedisProducter = new Jedis(R_HOST ...
- UI5-学习篇-18-云端UI5应用部署到Fiori Launchpad
UI5应用发布SCP 选择UI5应用项目,右键 Deploy - Deploy to SAP Cloud Platform 输入云平台子账号,项目名称,应用名称,如下图所示: 点击Open the r ...
- CSS VISUAL RULES
CSS VISUAL RULES Review Visual Rules Incredible work! You used CSS to alter text and images througho ...
- Linux用户名、用户组的相关命令
whoami 查看当前登录用户 id 用户名 查看用户名的id 及所属组 groups 查看当前登录用户的所有所属组 groups 用户名 查看指定用户的所有所属组 cat /etc/passwd ...