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

第三十二天打卡

import pandas as pd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
# 加载鸢尾花数据集
iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['target'] = iris.target  # 添加目标列(0-2类:山鸢尾、杂色鸢尾、维吉尼亚鸢尾)# 特征与目标变量
features = iris.feature_names  # 4个特征:花萼长度、花萼宽度、花瓣长度、花瓣宽度
target = 'target'  # 目标列名
# 划分训练集与测试集
X_train, X_test, y_train, y_test = train_test_split(df[features], df[target], test_size=0.2, random_state=42
)# 训练模型
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
# 首先要确保库的版本是最新的,因为我们看的是最新的文档,库的版本可以在github上查看
import  pdpbox
print(pdpbox.__version__)  # pdpbox版本
# 导入这个类
# 选择待分析的两个特征
feature1 = 'petal length (cm)'
feature2 = 'sepal length (cm)'
feature1_name = feature1
feature2_name = feature2
# 初始化交互目标
from pdpbox.info_plots import InteractTargetPlot  # 导入交互目标图类
# 初始化交互目标图
interact_plot = InteractTargetPlot(df=df,  # 原始数据features=[feature1, feature2],  # 两个特征feature_names=[feature1_name, feature2_name],  # 特征名称target='target',  # 目标变量grid_types=['percentile', 'percentile'],  # 两个特征都使用百分位分桶num_grid_points=[10, 10]  # 每个特征划分为10个桶
)
fig, axes, summary_df = interact_plot.plot(which_classes=None,  # 绘制所有类别show_percentile=True,  # 显示百分位线engine='plotly',template='plotly_white'
)# 手动设置图表尺寸(单位:像素)
fig.update_layout(width=800,  # 宽度800像素height=600,  # 高度500像素title=dict(text=f'InteractTargetPlot', x=0.5)  # 居中标题
)fig.show()

@浙大疏锦行 

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

相关文章:

  • 构建基于全面业务数据的大数据与大模型企业护城河战略
  • 【Linux】网络基础3
  • JUC入门(五)
  • 进程、线程和协程切换的比喻
  • 【分治】归并排序:递归版 非递归版
  • IDC机房交换机紧急更换的流程和注意事项
  • torch.gather()和torch.sort
  • 火语言UI组件--控件函数调用
  • 免费开源的图片分割小工具
  • RT-Thread源码阅读(1)——基本框架
  • 通过云服务器实现异地组网 部署WireGuard
  • 【机器学习】 关于外插修正随机梯度方法的数值实验
  • 听脑AI:革新沟通方式,开启高效信息时代
  • 核实发票的真实性与合法性-发票查验接口-虚假发票防范
  • 关于Newtonsoft版本不兼容问题处理
  • sentinel滑动时间窗口算法详解
  • 系统性能分析基本概念(3) : Tuning Efforts
  • imuerrset
  • PT8P2104触控型8Bit MCU
  • 【Django Serializer】一篇文章详解 Django 序列化器
  • deep-rtsp 摄像头rtsp配置工具
  • 高频与超高频RFID读写器技术应用差异解析
  • 论文解读: 2018-Detection of spam reviews: a sentiment analysis approach
  • 宝尊电商一季度净收入21亿元 品牌管理收入同比大增
  • 冲刺卷软考总结-案例分析
  • 地信GIS专业关于学习、考研、就业方面的一些问题答疑
  • Windows系统下Docker安装青龙面板
  • 常见高危端口解析:网络安全中的“危险入口”
  • 101个α因子#15
  • CentOS7安装 PHP-FPM 7.4