机器学习基础自学四(混沌矩阵)

本文介绍了一个使用Logistic回归预测糖尿病的机器学习模型。通过交叉验证评估了模型的对数损失和AUC值,展示了如何从数据集中分离特征和标签,并应用KFold进行模型训练和验证。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

from pandas import read_csv
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix#混沌矩阵
from sklearn.model_selection import train_test_split

# 导入数据
filename =  'D:\example\MachineLearning-master\pima_data.csv'
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
data = read_csv(filename, names=names)
# 将数据分为输入数据和输出结果
array = data.values
X = array[:, 0:8]
Y = array[:, 8]
num_folds = 10
seed = 7
kfold = KFold(n_splits=num_folds, random_state=seed)
model = LogisticRegression()

scoring = 'neg_log_loss'#对数损失函数,值越小,模型越好
result = cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
print('neg_log_loss %.3f (%.3f)' % (result.mean(), result.std()))


scoring = 'roc_auc'#AUC图,值越大,诊断准确性越高
result = cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
print('AUC %.3f (%.3f)' % (result.mean(), result.std()))

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值