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

合肥网站建设市场做薆视频网站

合肥网站建设市场,做薆视频网站,制作网页倒计时按钮,app开发公司办公室设计下载文中数据、代码、绘图结果 文章目录 关于数据绘图函数完整可运行的代码运行结果 关于数据 如果想知道本文的关联规则数据是怎么来的#xff0c;请阅读这篇文章 绘图函数 Python中似乎没有很方便的绘制网络图的函数。 下面是本人自行实现的绘图函数#xff0c;如果想…下载文中数据、代码、绘图结果 文章目录 关于数据绘图函数完整可运行的代码运行结果 关于数据 如果想知道本文的关联规则数据是怎么来的请阅读这篇文章 绘图函数 Python中似乎没有很方便的绘制网络图的函数。 下面是本人自行实现的绘图函数如果想要运行请点击上文的链接下载数据和代码。 传入一个关联规则数据的DataFrame这个DataFrame应该包含三列数据antecedentsconsequentsconfidence分别代表前件后件置信度。 def plot_rules_net(rules: pd.DataFrame):import matplotlib.patches as patches# 假设你有一个包含所有药材的列表items list(set([item for sublist in rules[antecedents].tolist() rules[consequents].tolist() for item in sublist]))# 计算药材数量确定顶点数n_items len(items)# 创建一个正n_items边形的顶点坐标radius 5 # 可以调整半径angle np.linspace(0, 2 * np.pi, n_items, endpointFalse)x radius * np.cos(angle)y radius * np.sin(angle)# 绘制正多边形和顶点fig, ax plt.subplots(figsize(10, 10))polygon patches.RegularPolygon((0, 0), n_items, radiusradius, fillFalse, edgecolork)ax.add_patch(polygon)def get_label_position(angle):label_offset_value 0.2 # 定义一个变量来存储偏移量# 根据角度确定文本标签的对齐方式和位置if angle np.pi / 2:ha, va center, bottomoffset np.array([label_offset_value, label_offset_value])elif angle np.pi:ha, va center, bottomoffset np.array([-label_offset_value, label_offset_value])elif angle 3 * np.pi / 2:ha, va center, topoffset np.array([-label_offset_value, -label_offset_value])else:ha, va center, topoffset np.array([label_offset_value, -label_offset_value])return ha, va, offset# 在绘制顶点的循环中调整文本位置for (i, j), label, angle in zip(zip(x, y), items, angle):ha, va, offset get_label_position(angle)ax.plot(i, j, o, markersize10)ax.text(i offset[0], j offset[1], label, fontsize12, haha, vava)# 获取confidence的最小值和最大值min_confidence rules[confidence].min()max_confidence rules[confidence].max()# 使用colormap - 可以根据需要选择合适的colormap# 这里我们使用Greens因为你想要的是颜色越深表示权重越大cmap plt.get_cmap(Greens)# 线性映射函数将confidence值映射到0-1之间用于colormapdef get_color(confidence):return cmap((confidence - min_confidence) / (max_confidence - min_confidence))# 绘制边for _, row in rules.iterrows():antecedents row[antecedents]consequents row[consequents]confidence row[confidence]for antecedent in antecedents:for consequent in consequents:start_idx items.index(antecedent)end_idx items.index(consequent)start_point (x[start_idx], y[start_idx])end_point (x[end_idx], y[end_idx])color get_color(confidence)# 修改箭头的绘制方式使其从节点边缘出发ax.annotate(,xyend_point, xytextstart_point,arrowpropsdict(arrowstyle-, colorcolor,shrinkA5, shrinkB5, # shrinkA和shrinkB应该是半径的大小不是索引connectionstylearc3),)ax.set_xlim([-radius * 1.1, radius * 1.1])ax.set_ylim([-radius * 1.1, radius * 1.1])ax.axis(off) # 隐藏坐标轴plt.suptitle(前24个最高频次药物的关联规则图, fontsize20) # 主标题plt.xlabel(颜色深代表置信度高, fontsize14) # X轴标签save_path os.path.join(., 关联规则网络图.jpg)plt.savefig(save_path)plt.show() 完整可运行的代码 下方就是完整可运行的代码在本文的下载链接中也一并包含如有需要请复制并运行。 import osimport matplotlib import numpy as np import pandas as pd from matplotlib import pyplot as pltplt.rcParams[font.sans-serif] [Simhei] # 显示中文标签 plt.rcParams[axes.unicode_minus] Falsedef plot_rules_net(rules: pd.DataFrame):import matplotlib.patches as patches# 假设你有一个包含所有药材的列表items list(set([item for sublist in rules[antecedents].tolist() rules[consequents].tolist() for item in sublist]))# 计算药材数量确定顶点数n_items len(items)# 创建一个正n_items边形的顶点坐标radius 5 # 可以调整半径angle np.linspace(0, 2 * np.pi, n_items, endpointFalse)x radius * np.cos(angle)y radius * np.sin(angle)# 绘制正多边形和顶点fig, ax plt.subplots(figsize(10, 10))polygon patches.RegularPolygon((0, 0), n_items, radiusradius, fillFalse, edgecolork)ax.add_patch(polygon)def get_label_position(angle):label_offset_value 0.2 # 定义一个变量来存储偏移量# 根据角度确定文本标签的对齐方式和位置if angle np.pi / 2:ha, va center, bottomoffset np.array([label_offset_value, label_offset_value])elif angle np.pi:ha, va center, bottomoffset np.array([-label_offset_value, label_offset_value])elif angle 3 * np.pi / 2:ha, va center, topoffset np.array([-label_offset_value, -label_offset_value])else:ha, va center, topoffset np.array([label_offset_value, -label_offset_value])return ha, va, offset# 在绘制顶点的循环中调整文本位置for (i, j), label, angle in zip(zip(x, y), items, angle):ha, va, offset get_label_position(angle)ax.plot(i, j, o, markersize10)ax.text(i offset[0], j offset[1], label, fontsize12, haha, vava)# 获取confidence的最小值和最大值min_confidence rules[confidence].min()max_confidence rules[confidence].max()# 使用colormap - 可以根据需要选择合适的colormap# 这里我们使用Greens因为你想要的是颜色越深表示权重越大cmap plt.get_cmap(Greens)# 线性映射函数将confidence值映射到0-1之间用于colormapdef get_color(confidence):return cmap((confidence - min_confidence) / (max_confidence - min_confidence))# 绘制边for _, row in rules.iterrows():antecedents row[antecedents]consequents row[consequents]confidence row[confidence]for antecedent in antecedents:for consequent in consequents:start_idx items.index(antecedent)end_idx items.index(consequent)start_point (x[start_idx], y[start_idx])end_point (x[end_idx], y[end_idx])color get_color(confidence)# 修改箭头的绘制方式使其从节点边缘出发ax.annotate(,xyend_point, xytextstart_point,arrowpropsdict(arrowstyle-, colorcolor,shrinkA5, shrinkB5, # shrinkA和shrinkB应该是半径的大小不是索引connectionstylearc3),)ax.set_xlim([-radius * 1.1, radius * 1.1])ax.set_ylim([-radius * 1.1, radius * 1.1])ax.axis(off) # 隐藏坐标轴plt.suptitle(前24个最高频次药物的关联规则图, fontsize20) # 主标题plt.xlabel(颜色深代表置信度高, fontsize14) # X轴标签save_path os.path.join(., 关联规则网络图.jpg)plt.savefig(save_path)plt.show()freq pd.read_excel(r万条处方的药物出现频次.xlsx)fd {k : v for _, (k, v) in freq.iterrows()}# 指定保留前24最高频次的中药材 most_freq_num 24 top_24_herbs sorted(fd, keylambda x: fd.get(x), reverseTrue)[:most_freq_num]# 读取关联规则分析的结果 rules pd.read_excel(关联规则分析结果.xlsx) rules[antecedents] rules[antecedents].apply(lambda x: x.split(, )) rules[consequents] rules[consequents].apply(lambda x: x.split(, ))# 过滤关联规则仅保留包含这24种药物的规则 filtered_rules rules[rules[antecedents].apply(lambda x: any(item in x for item in top_24_herbs)) rules[consequents].apply(lambda x: any(item in x for item in top_24_herbs))]plot_rules_net(filtered_rules) 运行结果 颜色越粗置信度越高。 我们可以看到砂仁和白芍还有荷叶和连翘等等有着很高的置信度。
http://www.zqtcl.cn/news/147373/

相关文章:

  • 网站制作报价被哪些因素影响建设银行官方网站首页个人登录
  • 免费网站怎么建谁能给个网站谢谢
  • 吴忠网站建设家里面的服务器可以做网站吗
  • 这是我自己做的网站做网站前台要学什么课程
  • 程序网站开发建设隔离变压器移动网站
  • 网站设置不发送消息怎么设置回来用typecho做的网站
  • 网站机房建设嵌入式培训机构哪家好
  • 购物网站页面设计图片网站 签约
  • 上海网站改版方案网站邮件设置
  • 如何在自己网站添加链接高端品牌logo图片
  • 网站建设找c宋南南app软件设计
  • 龙岗网站推广seo 0xu
  • 成都做网站微网站后台录入
  • 开发区网站建设山东房地产新闻
  • 手机如何搭建网站网站菜单导航
  • 网站建设丿金手指专业社交投票论坛网站开发
  • 做一套网站开发多少钱设计高端的国外网站
  • 有没有网站做lol网站的网页设计实验报告书
  • 网站后台域名重庆好的seo平台
  • 文化建设设计公司网站跨境电商亚马逊
  • 建设企业网站官网下载中心游戏网站开发设计报告
  • 外贸网站导航栏建设技巧专做奢侈品品牌的网站
  • 网站开发工程师资格证网站建设代理都有哪些
  • 汕头网站建设技术托管wordpress faq
  • 外贸网站建设系统能联系做仿瓷的网站
  • 阿里云网站域名绑定做网站的需要哪些职位
  • cnnic网站备案dnf网站上怎么做商人
  • 怎么做微拍网站代理记账公司注册
  • 长宁深圳网站建设公司建材公司网站建设方案
  • 做网站哪些软件比较好wordpress的留言功能