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

day31 5月29日

今日的示例代码包含2个部分

  1. notebook文件夹内的ipynb文件,介绍下今天的思路
  2. 项目文件夹中其他部分:拆分后的信贷项目,学习下如何拆分的,未来你看到的很多大项目都是类似的拆分方法

知识点回顾

  1. 规范的文件命名
  2. 规范的文件夹管理
  3. 机器学习项目的拆分
  4. 编码格式和类型注解

作业:尝试针对之前的心脏病项目ipynb,将他按照今天的示例项目整理成规范的形式,思考下哪些部分可以未来复用。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns from sklearn.ensemble import RandomForestClassifier from sklearn.tree import DecisionTreeClassifierfrom sklearn.tree import export_graphviz from sklearn.metrics import roc_curve, auc 
from sklearn.metrics import classification_report from sklearn.metrics import confusion_matrix from sklearn.model_selection import train_test_split np.random.seed(123) 
pd.options.mode.chained_assignment = None  %matplotlib inline
sns.set(palette = 'pastel', rc = {"figure.figsize": (10,5), "axes.titlesize" : 14,    "axes.labelsize" : 12,    "xtick.labelsize" : 10,   "ytick.labelsize" : 10 }) 
a = sns.countplot(x = 'target', data = dt)              
a.set_title('Distribution of Presence of Heart Disease') 
a.set_xticklabels(['Absent', 'Present'])                 
plt.xlabel("Presence of Heart Disease")                  plt.show()
g = sns.countplot(x = 'age', data = dt) 
g.set_title('Distribution of Age')      
plt.xlabel('Age')                       
b = sns.countplot(x = 'target', data = dt, hue = 'sex')         
plt.legend(['Female', 'Male'])                                    
b.set_title('Distribution of Presence of Heart Disease by Sex')   
b.set_xticklabels(['Absent', 'Present'])plt.show()
sns.distplot(dt['chol'].dropna(), kde=True, color='darkblue', bins=40)
dt['sex'][dt['sex'] == 0] = 'female'
dt['sex'][dt['sex'] == 1] = 'male'dt['chest_pain_type'][dt['chest_pain_type'] == 1] = 'typical angina'
dt['chest_pain_type'][dt['chest_pain_type'] == 2] = 'atypical angina'
dt['chest_pain_type'][dt['chest_pain_type'] == 3] = 'non-anginal pain'
dt['chest_pain_type'][dt['chest_pain_type'] == 4] = 'asymptomatic'dt['fasting_blood_sugar'][dt['fasting_blood_sugar'] == 0] = 'lower than 120mg/ml'
dt['fasting_blood_sugar'][dt['fasting_blood_sugar'] == 1] = 'greater than 120mg/ml'dt['rest_ecg'][dt['rest_ecg'] == 0] = 'normal'
dt['rest_ecg'][dt['rest_ecg'] == 1] = 'ST-T wave abnormality'
dt['rest_ecg'][dt['rest_ecg'] == 2] = 'left ventricular hypertrophy'dt['exercise_induced_angina'][dt['exercise_induced_angina'] == 0] = 'no'
dt['exercise_induced_angina'][dt['exercise_induced_angina'] == 1] = 'yes'dt['st_slope'][dt['st_slope'] == 1] = 'upsloping'
dt['st_slope'][dt['st_slope'] == 2] = 'flat'
dt['st_slope'][dt['st_slope'] == 3] = 'downsloping'dt['thalassemia'][dt['thalassemia'] == 1] = 'normal'
dt['thalassemia'][dt['thalassemia'] == 2] = 'fixed defect'
dt['thalassemia'][dt['thalassemia'] == 3] = 'reversable defect'
model = RandomForestClassifier(max_depth=5, n_estimators=10)    
model.fit(X_train, y_train)                                     
y_predict = model.predict(X_test)
y_pred_quant = model.predict_proba(X_test)[:, 1]
y_pred_bin = model.predict(X_test)
total=sum(sum(confusion_matrix))sensitivity = confusion_matrix[0,0]/(confusion_matrix[0,0]+confusion_matrix[1,0])
print('灵敏度 : ', sensitivity )specificity = confusion_matrix[1,1]/(confusion_matrix[1,1]+confusion_matrix[0,1])
print('特异度 : ', specificity)

 

http://www.xdnf.cn/news/719263.html

相关文章:

  • python打卡第36天
  • WPF中自定义消息弹窗
  • 小白畅通Linux之旅-----Linux安全管理
  • Ubuntu系统下Docker部署Dify保姆级教程:实现内网穿透远程访问
  • 超声波清洗机的作用是什么?使用超声波清洗机可以去除毛刺吗?
  • 非常好看网站维护带倒计时模板+维护结束模板
  • [嵌入式实验]实验一:点亮LED
  • Cisco Packer Tracer 中 VLAN 与三层交换机
  • UDS TP层参数
  • 【面板数据】各地区新型数字基础设施数据集(2002-2025年)
  • Day 39
  • 结构体对齐和结构体相关宏
  • day39 图像数据与显存
  • Cadence Innvous导出GDS没有STDCELL/IO/NET/VIA问题的解决方法
  • 输电线路的“智慧之眼”:全天候可视化监测如何赋能电网安全运维
  • Cmake编译glog成功并在QT中测试成功步骤
  • Mac本地安装MySQL jdbc Driver
  • 性能测试-jmeter实战1
  • R²AIN SUITE 驱动制造业变革:从灯塔实践到企业级落地方案
  • [Vue2]判断引用组件是否注册了 $emit 对应的事件
  • 网络摄像机POE交换机选型指南:技术参数与场景适配深度解析
  • 使用C# 快速删除Excel表格中的重复行数据-详解
  • HALCON常用算子
  • 【读代码】BabyAGI:自我构建的自主代理框架深度解析
  • Linux入门
  • C语言中函数指针和指针函数的定义及用法
  • 【leetcode】19. 删除链表的倒数第N个节点
  • CppCon 2014 学习第3天:Viewing the world through array-shaped glasses
  • 计算机网络常见体系结构、分层必要性、分层设计思想以及专用术语介绍
  • Mybatis(Plus)对JSON / Array类型进行序列化