逻辑回归之癌症预测

coding=utf-8

“”"
author:lei
function: 逻辑回归做二分类
“”"

import pandas as pd
from sklearn.linear_model import LogisticRegression
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import classification_report

def logistic():
“”"
逻辑回归做二分类进行癌症预测
:return:
“”"
column = ["{}".format(i) for i in range(11)]

# 读取数据
data = pd.read_csv("./data/breast-cancer-wisconsin.data")

# 缺失值进行处理
data = data.replace(to_replace="?", value=np.nan)

data = data.dropna()
# print(data)

# 进行数据的分割
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)

print(lg.coef_)

y_predict = lg.predict(x_test)

print("准确率:", lg.score(x_test, y_test))

print("召回率:", classification_report(y_test, y_predict, labels=[2, 4], target_names=["良性", "恶性"]))

if name == ‘main’:
logistic()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值