当前位置: 首页 > wzjs >正文

南京做网站哪家公司好b2b国际贸易平台

南京做网站哪家公司好,b2b国际贸易平台,网页都有哪些,南宁购物网站建设一、 题目要求: 给定以下二分类模型的预测结果,手动绘制ROC曲线并计算AUC值: y_true [0, 1, 0, 1, 0, 1] # 真实标签(0负类,1正类) y_score [0.2, 0.7, 0.3, 0.6, 0.1, 0.8] # 模型预测得分 代码展示…

一、

题目要求:

给定以下二分类模型的预测结果,手动绘制ROC曲线并计算AUC值:

y_true = [0, 1, 0, 1, 0, 1] # 真实标签(0=负类,1=正类)

y_score = [0.2, 0.7, 0.3, 0.6, 0.1, 0.8] # 模型预测得分

代码展示:

import matplotlib.pyplot as plt
from sklearn.metrics import roc_curvey_true = [0,1,0,1,0,1]
y_score = [0.2,0.7,0.3,0.6,0.1,0.8]fpr,tpr,_ = roc_curve(y_true,y_score)plt.figure(figsize=(8,9))
plt.plot(fpr,tpr,color="b")
plt.plot([0,1],[0,1],color="r",linestyle="--")
plt.xlabel("fpr")
plt.ylabel("tpr")
plt.grid()
plt.show()

结果展示:

 

 二、

题目要求

处理有相同预测得分的情况:

y_true = [1, 0, 0, 1, 1, 0, 1, 0]

y_score = [0.8, 0.5, 0.5, 0.7, 0.6, 0.5, 0.9, 0.3]

代码展示:

import matplotlib.pyplot as plt
from sklearn.metrics import roc_curvey_true = [1, 0, 0, 1, 1, 0, 1, 0]
y_score = [0.8, 0.5, 0.5, 0.7, 0.6, 0.5, 0.9, 0.3]fpr,tpr,_ = roc_curve(y_true,y_score)plt.figure(figsize=(8,9))
plt.plot(fpr,tpr,color="b")
plt.plot([0,1],[0,1],color="r",linestyle="--")
plt.xlabel("fpr")
plt.ylabel("tpr")
plt.grid()
plt.show()

结果展示:

 

三、

题目背景

在信用卡欺诈检测中,正常交易(负类)远多于欺诈交易(正类)。给定以下模拟数据:

y_true = [0, 0, 0, 0, 0, 0, 1, 0, 1, 0] # 2个欺诈(正类),8个正常(负类)

y_score = [0.1, 0.2, 0.15, 0.05, 0.3, 0.25, 0.9, 0.4, 0.6, 0.1] # 模型输出的欺诈概率

题目要求

  1. 手动计算所有(FPR, TPR)点
  2. 绘制ROC曲线
  3. 观察类别不平衡对曲线形状的影响

代码展示:

import matplotlib.pyplot as plt
from sklearn.metrics import roc_curvey_true = [0, 0, 0, 0, 0, 0, 1, 0, 1, 0]  # 2个欺诈(正类),8个正常(负类)
y_score = [0.1, 0.2, 0.15, 0.05, 0.3, 0.25, 0.9, 0.4, 0.6, 0.1]  # 模型输出的欺诈概率fpr,tpr,_ = roc_curve(y_true,y_score)plt.figure(figsize=(8,9))
plt.plot(fpr,tpr,color="b")
plt.plot([0,1],[0,1],color="r",linestyle="--")
plt.xlabel("fpr")
plt.ylabel("tpr")
plt.grid()
plt.show()

结果展示:

 

四、

使用Kaggle上的“Pima Indians Diabetes Database”数据集来进行逻辑回归的练习。该数据集的链接如下:Pima Indians Diabetes Database

‌练习场景描述‌:

你是一家医疗机构的数据分析师,你的任务是分析Pima Indians Diabetes Database数据集,以预测患者是否患有糖尿病。数据集包含了一系列与患者健康相关的指标,如怀孕次数、葡萄糖浓度、血压等。你需要使用逻辑回归模型来训练一个分类器,以根据这些指标预测患者是否患有糖尿病。

‌具体步骤‌:

  1. 使用pandas库加载数据集,并进行初步的数据探索,了解数据集的字段和分布情况。
  2. 对数据进行预处理,包括处理缺失值、标准化或归一化特征值等。
  3. 使用numpy库进行特征选择或特征工程,以提高模型的性能。
  4. 划分训练集和测试集,使用训练集训练逻辑回归模型,并使用测试集评估模型的性能。
  5. 使用matplotlib库绘制ROC曲线或混淆矩阵,以直观展示模型的分类效果。
  6. 根据评估结果调整模型的参数,以提高模型的性能。

‌题目‌:

基于上述练习场景,请完成以下任务:

  1. 加载Pima Indians Diabetes Database数据集,并进行初步的数据探索。
  2. 对数据进行预处理,包括处理缺失值和标准化特征值。
  3. 使用逻辑回归模型进行训练,并评估模型的性能。
  4. 绘制ROC曲线,展示模型的分类效果。
  5. 根据你的理解,提出至少一个改进模型性能的方法,并尝试实现。

 代码展示:

import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_curve
from sklearn.model_selection import train_test_split, GridSearchCV
from sklearn.preprocessing import StandardScalerdf = pd.read_csv("./data/diabetes.csv",encoding="utf-8")
print(df.head())
print(df.shape)df = df.dropna(axis=0)x = df.drop("Outcome",axis=1)
y = df["Outcome"]x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=22)transfer = StandardScaler()
x_train = transfer.fit_transform(x_train)
x_test = transfer.fit_transform(x_test)estimator = LogisticRegression()
estimator.fit(x_train,y_train)y_predict = estimator.predict(x_test)
print("预测值和真实的对比:",y_predict == y_test)ret = estimator.score(x_test,y_test)
print("准确率:",ret)y_pred_proba = estimator.predict_proba(x_test)[:, 1]
fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba)plt.figure(figsize=(8,9))
plt.plot(fpr,tpr,color="b")
plt.plot([0,1],[0,1],color="r",linestyle="--")
plt.xlabel("fpr")
plt.ylabel("tpr")
plt.grid()
plt.show()param_grid = {'C': [0.1, 1, 10, 100],'penalty': ['l1', 'l2'],'solver': ['liblinear', 'saga']
}
grid_search = GridSearchCV(LogisticRegression(), param_grid, cv=5)
grid_search.fit(x_train, y_train)best_estimator = grid_search.best_estimator_
best_ret = best_estimator.score(x_test, y_test)
print("调整参数后模型的准确率:", best_ret)

 结果展示:

预测值和真实的对比: 645    False
767     True
31      True
148    False
59      True...  
30      True
158     True
167     True
582    False
681     True
Name: Outcome, Length: 154, dtype: bool
准确率: 0.7402597402597403
调整参数后模型的准确率: 0.7402597402597403

http://www.dtcms.com/wzjs/237343.html

相关文章:

  • 后端工资一般比前端高吗湖北搜索引擎优化
  • 做网站都需要年服务费吗百度首页优化
  • 网站上怎样做超链接网店关键词怎么优化
  • 深圳 网站建设培训学校百度员工收入工资表
  • 网站建设前端学什么语言百度指数在哪里看
  • php 公安网站源码广告推销网站
  • 天门市住房和城乡建设委员会网站小红书推广方案
  • 湘潭做网站口碑好磐石网络推广营销方案
  • 产品企业网站的优化建议
  • 北京市人大网站建设白杨seo课程
  • 网站开发要学哪些新型网络营销模式
  • 怎么做网站后期推广朋友圈营销
  • 怎么建立网站免费的seo资源网站排名
  • 三水顺德网站建设谷歌搜索引擎入口手机版
  • 网站建设中 什么意思seo根据什么具体优化
  • 东台专业做网站的公司班级优化大师下载安装
  • wordpress自动排版seo优化点击软件
  • wordpress域名防封插件优化营商环境心得体会
  • 淘客网站超级搜怎么做热狗seo外包
  • wordpress怎么做商城网站网站关键词优化工具
  • 成年做羞羞的视频网站百度获客平台
  • 联雅网站建设如何做外贸网站的推广
  • 网站怎么做啊新闻稿在线
  • 松江网站建设公司小学生班级优化大师
  • 网站策划书包括哪几个步骤一元友情链接平台
  • 做网站挣钱来个好心人指点一下呗抖音搜索seo代理
  • 合肥手机网站制作谷歌优化
  • 怎么建设网站百度搜索的到推广产品的渠道
  • 山海关城乡建设局网站淘宝seo对什么内容优化
  • 班级网站建设组织机构本地推广平台有哪些