逻辑回归代码

Numpy数组的创建

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from sklearn.model_selection import train_test_split
# 划分数据集
X = credit.iloc[:,0:24]
y = credit.iloc[:,24]
y[y != 1] = 0
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=1/10, random_state=9)
print('数据集样本数:{},训练集样本数:{},测试集样本数:{}'.format(len(X), len(X_train), len(X_test)))

from sklearn.linear_model import LogisticRegression
lr = LogisticRegression(penalty='l2', C=1.0)
lr.fit(X_train, y_train)
y_pred1 = lr.predict(X_test)                # 预测分类类别
print(y_pred1)
y_pred1_p = lr.predict_proba(X_test)        # 预测分类概率
print(y_pred1_p)
from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, roc_auc_score

# 准确率
print('准确率:{:.3f}'.format(accuracy_score(y_test, y_pred1)))

# 精确率
print('精确率:{:.3f}'.format(precision_score(y_test, y_pred1)))

# 召回率
print('召回率:{:.3f}'.format(recall_score(y_test, y_pred1)))

# F1print('F1值:{:.3f}'.format(f1_score(y_test, y_pred1)))

# AUC
print('AUC值:{:.3f}'.format(roc_auc_score(y_test, y_pred1)))

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值