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)))
# F1值
print('F1值:{:.3f}'.format(f1_score(y_test, y_pred1)))
# AUC
print('AUC值:{:.3f}'.format(roc_auc_score(y_test, y_pred1)))