[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-erdogant--bnlearn":3,"tool-erdogant--bnlearn":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",145895,2,"2026-04-08T11:32:59",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108111,"2026-04-08T11:23:26",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":77,"owner_email":76,"owner_twitter":76,"owner_website":78,"owner_url":79,"languages":80,"stars":89,"forks":90,"last_commit_at":91,"license":92,"difficulty_score":93,"env_os":94,"env_gpu":95,"env_ram":95,"env_deps":96,"category_tags":107,"github_topics":108,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":121,"updated_at":122,"faqs":123,"releases":159},5607,"erdogant\u002Fbnlearn","bnlearn","Python package for Causal Discovery by learning the graphical structure of Bayesian networks. Structure Learning, Parameter Learning, Inferences, Sampling methods.","bnlearn 是一个专为因果发现设计的 Python 开源库，旨在帮助用户通过数据学习贝叶斯网络的结构。在数据分析中，传统的相关性分析往往难以揭示变量间真实的因果关系，而 bnlearn 正是为了解决这一痛点而生。它提供了一套完整的流程，涵盖从网络结构学习、参数估计到因果推断及合成数据生成，让用户不仅能构建概率图模型，还能进行干预分析和反事实推理，从而真正理解数据背后的因果逻辑。\n\n考虑到概率图模型通常具有较高的使用门槛，bnlearn 特别封装了常用且高效的处理管道，大幅降低了操作复杂度。无论是需要探索变量间深层机制的数据科学家、从事因果推断研究的学者，还是希望将专家知识与数据相结合的开发者，都能从中受益。其核心亮点在于将复杂的结构学习算法（如基于约束或评分的方法）与直观的 API 相结合，并支持结合领域知识优化模型。如果你正在寻找一个既能处理复杂因果建模任务，又具备良好易用性的工具，bnlearn 值得加入你的技术栈。","[![Python](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fbnlearn)](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fbnlearn)\n[![PyPI Version](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fbnlearn)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fbnlearn\u002F)\n![GitHub Repo stars](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Ferdogant\u002Fbnlearn)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-green.svg)](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fblob\u002Fmaster\u002FLICENSE)\n[![Forks](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fforks\u002Ferdogant\u002Fbnlearn.svg)](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fnetwork)\n[![Open Issues](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fissues\u002Ferdogant\u002Fbnlearn.svg)](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues)\n[![Project Status](http:\u002F\u002Fwww.repostatus.org\u002Fbadges\u002Flatest\u002Factive.svg)](http:\u002F\u002Fwww.repostatus.org\u002F#active)\n[![Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_68299d45d5e3.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fbnlearn\u002F)\n[![Downloads](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_ecb53c5e5ba4.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fbnlearn)\n[![DOI](https:\u002F\u002Fzenodo.org\u002Fbadge\u002F231263493.svg)](https:\u002F\u002Fzenodo.org\u002Fbadge\u002Flatestdoi\u002F231263493)\n[![Docs](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSphinx-Docs-Green)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002F)\n[![Medium](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMedium-Blog-black)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#medium-blog)\n![GitHub repo size](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frepo-size\u002Ferdogant\u002Fbnlearn)\n[![Donate](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSupport%20this%20project-grey.svg?logo=github%20sponsors)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#)\n[![Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#colab-notebook)\n\n\n### \n\n\u003Cdiv>\n\n\u003Ca href=\"https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002F\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_5015298a2b6b.png\" width=\"175\" align=\"left\" \u002F>\u003C\u002Fa>\n``bnlearn`` is Python package for causal discovery by learning the graphical structure of Bayesian networks, parameter learning, inference, and sampling methods.\nBecause probabilistic graphical models can be difficult to use, ``Bnlearn`` contains the most-wanted pipelines. Navigate to [API documentations](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002F) for more detailed information. **⭐️ Star it if you like it ⭐️**\n\u003C\u002Fdiv>\n\n---\n\n### Key Features\n\n| Feature | Description | Medium | Gumroad\u002FPodcast |\n|--------|-------------|---|---|\n| [**Causal Discovery - Overview and Starters Guide**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html) | Learn the basics of causal modelling. |[link](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fthe-starters-guide-to-causal-structure-learning-with-bayesian-methods-in-python-e3b90f49c99c)|---|\n| [**Structure Learning**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html) | Learn the model structure from data or with expert knowledge. |[link](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fthe-complete-starter-guide-for-causal-discovery-using-bayesian-modeling-8853eb860d02)|---|\n| [**Causal Predictions**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html) | Learn to make causal predictions. |[link](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fwhy-prediction-isnt-enough-using-bayesian-models-to-change-the-outcome-5c9cf9f65a75)|---|\n| [**Parameter Learning**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FParameter%20learning.html) | Estimate model parameters (e.g., conditional probability distributions) from observed data. |[link](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fhuman-machine-collaboration-with-bayesian-modeling-learn-to-combine-knowledge-with-data-1ee9bcd67745)|---|\n| [**Causal Inference**](https:\u002F\u002Fpgmpy.org\u002Fexamples\u002FCausal%20Inference.html) | Compute interventional and counterfactual distributions using do-calculus. |[link](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fchat-with-your-dataset-using-bayesian-inferences-1afdbfd4bada)|---|\n| [**Generate Synthetic Data**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FSampling.html) | Generate synthetic data. |[link](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fsynthetic-data-the-essentials-of-data-generation-using-bayesian-sampling-6d072e97e09d)|---|\n| [**Discretize Data**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDiscretizing.html) | Discretize continuous datasets. |---|---|\n| [**Comparisons**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDiscretizing.html) | Comparison with other causal libraries. |[link](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fsix-causal-libraries-compared-which-bayesian-approach-finds-hidden-causes-in-your-data-9fa66fd02825)|---|\n\n---\n\n### Resources and Links\n- **Example Notebooks:** [Examples](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#google-colab-notebooks)\n- **Blog Posts:** [Medium](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#medium-blog-posts)\n- **Documentation:** [Website](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn)\n- **Bug Reports and Feature Requests:** [GitHub Issues](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues)\n\n---\n\n### The following functions are available after installation:\n\n| Feature | Description |\n|--------|-------------|\n| **Key Pipelines** | |\n|  [Structure learning](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html#exhaustivesearch) | ```bn.structure_learning.fit()``` |\n| [Parameter learning](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FParameter%20learning.html#parameter-learning-examples) | ```bn.parameter_learning.fit()``` |\n| [Inference](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FInference.html#examples-inference) | ```bn.inference.fit()``` |\n| [Make predictions](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FPredict.html) | ```bn.predict()``` |\n| [Generate Synthetic Data](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FSampling.html) | ```bn.sampling()``` |\n| [Compute Edge Strength](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Findependence_test.html) | ```bn.independence_test()``` |\n| **Key Functions** | |\n| [Imputations](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fimpute.html#) | ```bn.knn_imputer()``` |\n| [Discretizing](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDiscretizing.html#) | ```bn.discretize()``` |\n| [Check Model Parameters](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.check_model) | ```bn.check_model()``` |\n| [Create DAG](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.make_DAG) | ```bn.make_DAG()``` |\n| [Get Node Properties](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.get_node_properties) | ```bn.get_node_properties()``` |\n| [Get Edge Properties](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.get_edge_properties) | ```bn.get_edge_properties()``` |\n| [Get Parents From Edges](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.get_parents) | ```bn.get_parents()``` |\n| [Generate Default CPT per Node](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.generate_cpt) | ```bn.generate_cpt()``` |\n| [Generate Default CPTs for All Edges](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.build_cpts_from_structure) | ```bn.build_cpts_from_structure()``` |\n| **Make Plots** | |\n| [Plotting](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FPlot.html) | ```bn.plot()``` |\n| [Plot Graphviz](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.plot_graphviz) | ```bn.plot_graphviz()``` |\n| [Compare 2 Networks](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FPlot.html#comparison-of-two-networks) | ```bn.compare_networks()``` |\n| [Load DAG (bif files)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.import_DAG) | ```bn.import_DAG()``` |\n| [Load Examples](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.import_example) | ```bn.import_example()``` |\n| **Transformation Functions** | |\n| [Convert DAG to Undirected](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.to_undirected) | ```bn.to_undirected()``` |\n| [Convert to one-hot](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.df2onehot) | ```bn.df2onehot()``` |\n| [Convert Adjacency Matrix to Vector](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.adjmat2vec) | ```bn.adjmat2vec()``` |\n| [Convert Adjacency Matrix to Dictionary](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.adjmat2dict) | ```bn.adjmat2dict()``` |\n| [Convert Vector to Adjacency Matrix](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.vec2adjmat) | ```bn.vec2adjmat()``` |\n| [Convert DAG to Adjacency Matrix](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.dag2adjmat) | ```bn.dag2adjmat()``` |\n| [Convert DataFrame to Onehot](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FExample%20Datasets.html) | ```bn.df2onehot()``` |\n| [Convert Query to DataFrame](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.query2df) | ```bn.query2df()``` |\n| [Convert Vector to DataFrame](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.vec2df) | ```bn.vec2df()``` |\n| **Metrics** | |\n| [Compute Topological Ordering](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Ftopological_sort.html) | ```bn.topological_sort()``` |\n| [Compute Structure Scores](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure_scores.html) | ```bn.structure_scores()``` |\n| **General** | |\n| [Save Model](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fsaving%20and%20loading.html) | ```bn.save()``` |\n| [Load Model](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fsaving%20and%20loading.html) | ```bn.load()``` |\n| [Print CPTs](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.print_CPD) | ```bn.print_CPD()``` |\n\n---\n### Installation\n\n##### Install bnlearn from PyPI\n```bash\npip install bnlearn\n```\n##### Install bnlearn from github source\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\n```\n##### Load library\n```python\n# Import library\nimport bnlearn as bn\n```\n---\n\n### Code Examples\n\n```python\n\n    import bnlearn as bn\n    # Example dataframe sprinkler_data.csv can be loaded with: \n    df = bn.import_example()\n    # df = pd.read_csv('sprinkler_data.csv')\n\nCloudy  Sprinkler  Rain  Wet_Grass\n0         0          1     0          1\n1         1          1     1          1\n2         1          0     1          1\n3         0          0     1          1\n4         1          0     1          1\n..      ...        ...   ...        ...\n995       0          0     0          0\n996       1          0     0          0\n997       0          0     1          0\n998       1          1     0          1\n999       1          0     1          1\n\n\n    model = bn.structure_learning.fit(df)\n    # Compute edge strength with the chi-square test statistic\n    model = bn.independence_test(model, df)\n    G = bn.plot(model)\n```\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_d918dd498e79.png\" width=\"600\" \u002F>\n\u003C\u002Fp>\n\n\n```python\n\n# Example: Structure Learning\n\n    model_hc_bic  = bn.structure_learning.fit(df, methodtype='hc', scoretype='bic')\n    model_hc_k2   = bn.structure_learning.fit(df, methodtype='hc', scoretype='k2')\n    model_hc_bdeu = bn.structure_learning.fit(df, methodtype='hc', scoretype='bdeu')\n    model_ex_bic  = bn.structure_learning.fit(df, methodtype='ex', scoretype='bic')\n    model_ex_k2   = bn.structure_learning.fit(df, methodtype='ex', scoretype='k2')\n    model_ex_bdeu = bn.structure_learning.fit(df, methodtype='ex', scoretype='bdeu')\n    model_cl      = bn.structure_learning.fit(df, methodtype='cl', root_node='Wet_Grass')\n    model_tan     = bn.structure_learning.fit(df, methodtype='tan', root_node='Wet_Grass', class_node='Rain')\n\n# Example: Parameter Learning\n\n    import bnlearn as bn\n    # Import dataframe\n    df = bn.import_example()\n    # As an example we set the CPD at False which returns an \"empty\" DAG\n    model = bn.import_DAG('sprinkler', CPD=False)\n    # Now we learn the parameters of the DAG using the df\n    model_update = bn.parameter_learning.fit(model, df)\n    # Make plot\n    G = bn.plot(model_update)\n\n# Example: Inference\n\n    import bnlearn as bn\n    model = bn.import_DAG('sprinkler')\n    query = bn.inference.fit(model, variables=['Rain'], evidence={'Cloudy':1,'Sprinkler':0, 'Wet_Grass':1})\n    print(query)\n    print(query.df)\n    \n    # Lets try another inference\n    query = bn.inference.fit(model, variables=['Rain'], evidence={'Cloudy':1})\n    print(query)\n    print(query.df)\n\n```\n\n\u003Chr>\n\n\n### Star history\n\n[![Star History Chart](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_0e77579efa04.png)](https:\u002F\u002Fwww.star-history.com\u002F#erdogant\u002Fbnlearn&Date)\n\n### Contributors\nThank the contributors!\n\n\u003Cp align=\"left\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fgraphs\u002Fcontributors\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_e24f0af6231f.png\" \u002F>\n  \u003C\u002Fa>\n\u003C\u002Fp>\n\n### Maintainer\n* Erdogan Taskesen, github: [erdogant](https:\u002F\u002Fgithub.com\u002Ferdogant)\n* Contributions are welcome.\n* Yes! This library is entirely **free** but it runs on coffee! :) Feel free to support with a \u003Ca href=\"https:\u002F\u002Ferdogant.github.io\u002Fdonate\u002F?currency=USD&amount=5\">Coffee\u003C\u002Fa>.\n\n[![Buy me a coffee](https:\u002F\u002Fimg.buymeacoffee.com\u002Fbutton-api\u002F?text=Buy+me+a+coffee&emoji=&slug=erdogant&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff)](https:\u002F\u002Fwww.buymeacoffee.com\u002Ferdogant)\n","[![Python](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fbnlearn)](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fbnlearn)\n[![PyPI版本](https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fbnlearn)](https:\u002F\u002Fpypi.org\u002Fproject\u002Fbnlearn\u002F)\n![GitHub仓库星标数](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fstars\u002Ferdogant\u002Fbnlearn)\n[![许可证](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-green.svg)](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fblob\u002Fmaster\u002FLICENSE)\n[![复刻数](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fforks\u002Ferdogant\u002Fbnlearn.svg)](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fnetwork)\n[![未解决的问题](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Fissues\u002Ferdogant\u002Fbnlearn.svg)](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues)\n[![项目状态](http:\u002F\u002Fwww.repostatus.org\u002Fbadges\u002Flatest\u002Factive.svg)](http:\u002F\u002Fwww.repostatus.org\u002F#active)\n[![下载量](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_68299d45d5e3.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fbnlearn\u002F)\n[![下载量](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_ecb53c5e5ba4.png)](https:\u002F\u002Fpepy.tech\u002Fproject\u002Fbnlearn)\n[![DOI](https:\u002F\u002Fzenodo.org\u002Fbadge\u002F231263493.svg)](https:\u002F\u002Fzenodo.org\u002Fbadge\u002Flatestdoi\u002F231263493)\n[![文档](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSphinx-Docs-Green)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002F)\n[![Medium](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMedium-Blog-black)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#medium-blog)\n![GitHub仓库大小](https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frepo-size\u002Ferdogant\u002Fbnlearn)\n[![捐赠](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSupport%20this%20project-grey.svg?logo=github%20sponsors)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#)\n[![Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#colab-notebook)\n\n\n### \n\n\u003Cdiv>\n\n\u003Ca href=\"https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002F\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_5015298a2b6b.png\" width=\"175\" align=\"left\" \u002F>\u003C\u002Fa>\n``bnlearn`` 是一个用于因果发现的 Python 包，支持贝叶斯网络的图结构学习、参数学习、推理和采样方法。由于概率图模型通常较为复杂难用，``Bnlearn`` 提供了用户最需要的工作流。更多详细信息请访问 [API 文档](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002F)。**⭐️ 如果你喜欢它，请给它一颗星 ⭐️**\n\u003C\u002Fdiv>\n\n---\n\n### 核心功能\n\n| 功能 | 描述 | Medium | Gumroad\u002F播客 |\n|--------|-------------|---|---|\n| [**因果发现 - 概述与入门指南**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html) | 学习因果建模的基础知识。 |[链接](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fthe-starters-guide-to-causal-structure-learning-with-bayesian-methods-in-python-e3b90f49c99c)|---|\n| [**结构学习**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html) | 从数据中或结合专家知识学习模型结构。 |[链接](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fthe-complete-starter-guide-for-causal-discovery-using-bayesian-modeling-8853eb860d02)|---|\n| [**因果预测**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html) | 学习如何进行因果预测。 |[链接](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fwhy-prediction-isnt-enough-using-bayesian-models-to-change-the-outcome-5c9cf9f65a75)|---|\n| [**参数学习**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FParameter%20learning.html) | 根据观测数据估计模型参数（如条件概率分布）。 |[链接](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fhuman-machine-collaboration-with-bayesian-modeling-learn-to-combine-knowledge-with-data-1ee9bcd67745)|---|\n| [**因果推断**](https:\u002F\u002Fpgmpy.org\u002Fexamples\u002FCausal%20Inference.html) | 使用 do-calculus 计算干预和反事实分布。 |[链接](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fchat-with-your-dataset-using-bayesian-inferences-1afdbfd4bada)|---|\n| [**生成合成数据**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FSampling.html) | 生成合成数据。 |[链接](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fsynthetic-data-the-essentials-of-data-generation-using-bayesian-sampling-6d072e97e09d)|---|\n| [**数据离散化**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDiscretizing.html) | 对连续数据集进行离散化处理。 |---|---|\n| [**对比分析**](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDiscretizing.html) | 与其他因果推断库的比较。 |[链接](https:\u002F\u002Fmedium.com\u002Fdata-science-collective\u002Fsix-causal-libraries-compared-which-bayesian-approach-finds-hidden-causes-in-your-data-9fa66fd02825)|---|\n\n---\n\n### 资源与链接\n- **示例笔记本:** [示例](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#google-colab-notebooks)\n- **博客文章:** [Medium](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDocumentation.html#medium-blog-posts)\n- **文档:** [官网](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn)\n- **问题报告与功能请求:** [GitHub Issues](https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues)\n\n---\n\n### 安装后可用的功能如下：\n\n| 功能 | 描述 |\n|--------|-------------|\n| **关键流程** | |\n| [结构学习](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html#exhaustivesearch) | ```bn.structure_learning.fit()``` |\n| [参数学习](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FParameter%20learning.html#parameter-learning-examples) | ```bn.parameter_learning.fit()``` |\n| [推理](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FInference.html#examples-inference) | ```bn.inference.fit()``` |\n| [进行预测](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FPredict.html) | ```bn.predict()``` |\n| [生成合成数据](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FSampling.html) | ```bn.sampling()``` |\n| [计算边强度](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Findependence_test.html) | ```bn.independence_test()``` |\n| **关键函数** | |\n| [插补](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fimpute.html#) | ```bn.knn_imputer()``` |\n| [离散化](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FDiscretizing.html#) | ```bn.discretize()``` |\n| [检查模型参数](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.check_model) | ```bn.check_model()``` |\n| [创建有向无环图（DAG）](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.make_DAG) | ```bn.make_DAG()``` |\n| [获取节点属性](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.get_node_properties) | ```bn.get_node_properties()``` |\n| [获取边属性](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.get_edge_properties) | ```bn.get_edge_properties()``` |\n| [从边中获取父节点](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.get_parents) | ```bn.get_parents()``` |\n| [为每个节点生成默认的条件概率表（CPT）](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.generate_cpt) | ```bn.generate_cpt()``` |\n| [为所有边生成默认的条件概率表](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.build_cpts_from_structure) | ```bn.build_cpts_from_structure()``` |\n| **绘制图表** | |\n| [绘图](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FPlot.html) | ```bn.plot()``` |\n| [绘制 Graphviz 图](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.plot_graphviz) | ```bn.plot_graphviz()``` |\n| [比较两个网络](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FPlot.html#comparison-of-two-networks) | ```bn.compare_networks()``` |\n| [加载 DAG（bif 文件）](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.import_DAG) | ```bn.import_DAG()``` |\n| [加载示例数据](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.import_example) | ```bn.import_example()``` |\n| **转换函数** | |\n| [将 DAG 转换为无向图](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.to_undirected) | ```bn.to_undirected()``` |\n| [转换为独热编码](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.df2onehot) | ```bn.df2onehot()``` |\n| [将邻接矩阵转换为向量](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.adjmat2vec) | ```bn.adjmat2vec()``` |\n| [将邻接矩阵转换为字典](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.adjmat2dict) | ```bn.adjmat2dict()``` |\n| [将向量转换为邻接矩阵](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.vec2adjmat) | ```bn.vec2adjmat()``` |\n| [将 DAG 转换为邻接矩阵](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.dag2adjmat) | ```bn.dag2adjmat()``` |\n| [将 DataFrame 转换为独热编码](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FExample%20Datasets.html) | ```bn.df2onehot()``` |\n| [将查询转换为 DataFrame](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.query2df) | ```bn.query2df()``` |\n| [将向量转换为 DataFrame](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.vec2df) | ```bn.vec2df()``` |\n| **度量指标** | |\n| [计算拓扑排序](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Ftopological_sort.html) | ```bn.topological_sort()``` |\n| [计算结构评分](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure_scores.html) | ```bn.structure_scores()``` |\n| **通用功能** | |\n| [保存模型](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fsaving%20and%20loading.html) | ```bn.save()``` |\n| [加载模型](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fsaving%20and%20loading.html) | ```bn.load()``` |\n| [打印 CPT](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.print_CPD) | ```bn.print_CPD()``` |\n\n---\n### 安装\n\n##### 从 PyPI 安装 bnlearn\n```bash\npip install bnlearn\n```\n##### 从 GitHub 源代码安装 bnlearn\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\n```\n##### 加载库\n```python\n# 导入库\nimport bnlearn as bn\n```\n\n---\n\n### 代码示例\n\n```python\n\n    import bnlearn as bn\n    # 示例数据框 sprinkler_data.csv 可以通过以下方式加载：\n    df = bn.import_example()\n    # df = pd.read_csv('sprinkler_data.csv')\n\nCloudy  Sprinkler  Rain  Wet_Grass\n0         0          1     0          1\n1         1          1     1          1\n2         1          0     1          1\n3         0          0     1          1\n4         1          0     1          1\n..      ...        ...   ...        ...\n995       0          0     0          0\n996       1          0     0          0\n997       0          0     1          0\n998       1          1     0          1\n999       1          0     1          1\n\n\n    model = bn.structure_learning.fit(df)\n    # 使用卡方检验统计量计算边强度\n    model = bn.independence_test(model, df)\n    G = bn.plot(model)\n```\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_d918dd498e79.png\" width=\"600\" \u002F>\n\u003C\u002Fp>\n\n\n```python\n\n# 示例：结构学习\n\n    model_hc_bic  = bn.structure_learning.fit(df, methodtype='hc', scoretype='bic')\n    model_hc_k2   = bn.structure_learning.fit(df, methodtype='hc', scoretype='k2')\n    model_hc_bdeu = bn.structure_learning.fit(df, methodtype='hc', scoretype='bdeu')\n    model_ex_bic  = bn.structure_learning.fit(df, methodtype='ex', scoretype='bic')\n    model_ex_k2   = bn.structure_learning.fit(df, methodtype='ex', scoretype='k2')\n    model_ex_bdeu = bn.structure_learning.fit(df, methodtype='ex', scoretype='bdeu')\n    model_cl      = bn.structure_learning.fit(df, methodtype='cl', root_node='Wet_Grass')\n    model_tan     = bn.structure_learning.fit(df, methodtype='tan', root_node='Wet_Grass', class_node='Rain')\n\n# 示例：参数学习\n\n    import bnlearn as bn\n    # 导入数据框\n    df = bn.import_example()\n    # 以设置 CPD 为 False 为例，这将返回一个“空”的贝叶斯网络图\n    model = bn.import_DAG('sprinkler', CPD=False)\n    # 现在我们使用数据框来学习该贝叶斯网络图的参数\n    model_update = bn.parameter_learning.fit(model, df)\n    # 绘制图形\n    G = bn.plot(model_update)\n\n# 示例：推理\n\n    import bnlearn as bn\n    model = bn.import_DAG('sprinkler')\n    query = bn.inference.fit(model, variables=['Rain'], evidence={'Cloudy':1,'Sprinkler':0, 'Wet_Grass':1})\n    print(query)\n    print(query.df)\n    \n    # 再尝试一次推理\n    query = bn.inference.fit(model, variables=['Rain'], evidence={'Cloudy':1})\n    print(query)\n    print(query.df)\n\n```\n\n\u003Chr>\n\n\n### 星级历史\n\n[![星级历史图表](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_0e77579efa04.png)](https:\u002F\u002Fwww.star-history.com\u002F#erdogant\u002Fbnlearn&Date)\n\n### 贡献者\n感谢所有贡献者！\n\n\u003Cp align=\"left\">\n  \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fgraphs\u002Fcontributors\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_readme_e24f0af6231f.png\" \u002F>\n  \u003C\u002Fa>\n\u003C\u002Fp>\n\n### 维护者\n* 埃尔多甘·塔塞森，GitHub: [erdogant](https:\u002F\u002Fgithub.com\u002Ferdogant)\n* 欢迎大家贡献代码。\n* 是的！这个库完全**免费**，但它靠咖啡运行！:) 如果您愿意，请通过 \u003Ca href=\"https:\u002F\u002Ferdogant.github.io\u002Fdonate\u002F?currency=USD&amount=5\">一杯咖啡\u003C\u002Fa>给予支持。\n\n[![请我喝杯咖啡](https:\u002F\u002Fimg.buymeacoffee.com\u002Fbutton-api\u002F?text=Buy+me+a+coffee&emoji=&slug=erdogant&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff)](https:\u002F\u002Fwww.buymeacoffee.com\u002Ferdogant)","# bnlearn 快速上手指南\n\n`bnlearn` 是一个用于因果发现的 Python 库，专注于贝叶斯网络的结构学习、参数学习、推理及采样。它封装了常用的概率图模型管道，让开发者能轻松从数据中学习因果关系并进行预测。\n\n## 1. 环境准备\n\n*   **操作系统**：Windows, Linux, macOS\n*   **Python 版本**：支持 Python 3.x (推荐 3.8+)\n*   **前置依赖**：安装时会自动处理主要依赖（如 `pandas`, `numpy`, `pgmpy` 等）。\n    *   *注意*：若需使用 `plot_graphviz` 进行高级绘图，请确保系统已安装 Graphviz 软件并将其添加到环境变量 PATH 中。\n\n## 2. 安装步骤\n\n### 方式一：通过 PyPI 安装（推荐）\n\n国内用户建议使用清华或阿里镜像源以加速下载：\n\n```bash\npip install bnlearn -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n或使用官方源：\n\n```bash\npip install bnlearn\n```\n\n### 方式二：从 GitHub 源码安装（获取最新版本）\n\n```bash\npip install git+https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\n```\n\n### 验证安装\n\n在 Python 环境中导入库：\n\n```python\nimport bnlearn as bn\n```\n\n## 3. 基本使用\n\n以下是最简单的“结构学习”工作流：加载示例数据 -> 学习网络结构 -> 计算边强度 -> 可视化结果。\n\n### 最小化示例代码\n\n```python\nimport bnlearn as bn\n\n# 1. 加载内置示例数据 (sprinkler_data)\n# 实际使用中可替换为: df = pd.read_csv('your_data.csv')\ndf = bn.import_example()\n\n# 2. 结构学习：从数据中自动推断贝叶斯网络结构\nmodel = bn.structure_learning.fit(df)\n\n# 3. 独立性检验：计算边的强度 (使用卡方检验统计量)\nmodel = bn.independence_test(model, df)\n\n# 4. 可视化网络结构\nG = bn.plot(model)\n```\n\n### 进阶：指定算法进行结构学习\n\n`bnlearn` 支持多种结构学习算法（如爬山法 `hc`、穷举搜索 `ex`、Chow-Liu `cl` 等）和评分标准（如 `bic`, `k2`, `bdeu`）。\n\n```python\nimport bnlearn as bn\n\ndf = bn.import_example()\n\n# 使用爬山法 (Hill Climbing) 配合 BIC 评分\nmodel_hc_bic = bn.structure_learning.fit(df, methodtype='hc', scoretype='bic')\n\n# 使用穷举搜索 (Exhaustive Search) 配合 K2 评分\nmodel_ex_k2 = bn.structure_learning.fit(df, methodtype='ex', scoretype='k2')\n\n# 绘制对比或单独绘制\nbn.plot(model_hc_bic)\n```\n\n### 核心功能速查\n\n*   **参数学习**: `bn.parameter_learning.fit(model, df)`\n*   **因果推理**: `bn.inference.fit(model, variables=['Rain'], evidence={'Sprinkler': 1})`\n*   **生成合成数据**: `bn.sampling(model, n=1000)`\n*   **数据离散化**: `bn.discretize(df)`\n*   **保存\u002F加载模型**: `bn.save(model)`, `bn.load('model.zip')`","某电商数据科学团队正试图从海量用户行为日志中挖掘导致“高价值用户流失”的根本原因，以制定精准的留存策略。\n\n### 没有 bnlearn 时\n- 团队仅能依赖皮尔逊相关系数等统计指标，误将“同时发生”当作“因果关系”，导致资源错误投入到非关键因素上。\n- 面对数十个潜在影响变量（如加载延迟、客服响应、促销频率），缺乏自动化手段构建有向无环图，只能凭专家经验手动假设网络结构，效率极低且主观性强。\n- 无法量化“干预措施”的效果，例如难以回答“如果将页面加载速度提升 20%，流失率具体会下降多少”这类反事实问题。\n- 模型参数估计过程繁琐，需编写大量底层代码处理条件概率分布，且难以融合业务先验知识修正模型。\n\n### 使用 bnlearn 后\n- 利用结构学习算法自动从数据中挖掘出真实的因果图谱，精准识别出“客服响应慢”是导致流失的直接父节点，而非仅仅是相关现象。\n- 通过内置的多种搜索策略（如 Hill Climbing），快速在复杂变量空间中确定最优网络拓扑，将原本数周的建模周期缩短至几小时。\n- 借助 do-演算（do-calculus）功能直接模拟干预实验，定量计算出优化特定环节后的预期收益，为决策提供确凿的数据支撑。\n- 轻松实现参数学习与先验知识融合，既能从历史数据估算条件概率，又能将资深运营的经验规则嵌入模型，显著提升预测鲁棒性。\n\nbnlearn 将模糊的相关性分析升级为可解释、可干预的因果决策引擎，帮助团队从“猜测原因”转向“精准施策”。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Ferdogant_bnlearn_e344bfd3.png","erdogant","Erdogan","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Ferdogant_602d21ff.png","Machine Learning | Statistics | Bayesian | D3js | Visualizations",null,"Den Haag","https:\u002F\u002Ferdogant.github.io\u002F","https:\u002F\u002Fgithub.com\u002Ferdogant",[81,85],{"name":82,"color":83,"percentage":84},"Jupyter Notebook","#DA5B0B",91.6,{"name":86,"color":87,"percentage":88},"Python","#3572A5",8.4,617,56,"2026-04-07T08:10:55","NOASSERTION",1,"Linux, macOS, Windows","未说明",{"notes":97,"python":98,"dependencies":99},"该工具主要用于贝叶斯网络的结构学习、参数学习和因果推断，基于 CPU 运行即可，无需特殊 GPU 配置。可通过 pip 直接安装，支持导入 BIF 文件格式的 DAG 结构。建议配合 Jupyter Notebook 或 Google Colab 使用示例代码。","3.6+",[100,101,102,103,104,105,106],"pandas","numpy","scikit-learn","pgmpy","matplotlib","networkx","tqdm",[52,14],[109,110,111,112,113,114,115,116,117,118,119,120],"bayesian-inference","structure-learning","sampling-methods","dag","directed-acyclic-graph","parameter-learning","causal-models","causality-analysis","causal-networks","causal","machine-learning","python","2026-03-27T02:49:30.150509","2026-04-09T01:24:12.358505",[124,129,134,139,144,149,154],{"id":125,"question_zh":126,"answer_zh":127,"source_url":128},25454,"为什么使用 bnlearn 库的 TAN 算法与 pgmpy 的 treesearch 得到的结果不同？","这通常是因为评分类型（scoretype）设置不同导致的。请确保在 bnlearn 中显式指定评分类型，例如使用 `scoretype='bic'`、`scoretype='k2'` 或 `scoretype='bdeu'`。早期版本可能存在参数传递错误，建议更新到最新版本并检查代码中是否正确设置了该参数。","https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues\u002F38",{"id":130,"question_zh":131,"answer_zh":132,"source_url":133},25455,"bnlearn 支持处理连续型数据吗？是否需要先离散化？","是的，最新版本的 bnlearn 已经原生支持连续型数据建模，无需手动离散化。库中实现了 LiNGAM 方法（Direct 和 ICA）来处理连续变量。请先升级库：`pip install -U bnlearn`，然后参考官方文档中的“Continuous Data”章节使用相关功能。","https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues\u002F36",{"id":135,"question_zh":136,"answer_zh":137,"source_url":138},25456,"如何处理基因表达等连续生物数据，是否必须使用内置的离散化函数？","不需要强制使用内置离散化函数。虽然旧版本可能需要先构建图再离散化，但新版本已添加直接处理连续数据的功能（如 LiNGAM 方法）。您可以直接对连续数据进行建模而无需预先推断节点和边。请运行 `pip install -U bnlearn` 更新版本，并查看文档中关于连续数据处理的示例。","https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues\u002F94",{"id":140,"question_zh":141,"answer_zh":142,"source_url":143},25457,"bnlearn 是否支持处理缺失数据（类似 R 语言 bnlearn 包的功能）？","支持。bnlearn 现已集成 MICE（多重插补）功能用于处理缺失数据，该功能由社区贡献者实现。使用前请更新库：`pip install -U bnlearn`。具体用法可参考官方文档的 impute 页面。注意当前实现主要支持定量数据，若需处理分类数据可能需要结合其他工具或自定义贝叶斯模型迭代预测。","https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues\u002F81",{"id":145,"question_zh":146,"answer_zh":147,"source_url":148},25458,"使用 interactive=True 绘图时出现 ValueError: tooltip text 长度与节点数不匹配，如何解决？","该错误是由于节点名称在 d3blocks 和 bnlearn 交互式绘图模块中清洗规则不一致导致的。维护者已修复此问题，统一了节点名称的处理逻辑。请升级到最新版本：`pip install -U bnlearn`，即可解决该报错。如果节点名包含下划线或其他特殊字符，更新后也应能正常显示。","https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues\u002F98",{"id":150,"question_zh":151,"answer_zh":152,"source_url":153},25459,"在 Jupyter Notebook 或 Colab 中使用 bn.plot 绘制交互式图表时显示空白，怎么办？","这是由于 CDN 资源加载问题导致的。维护者已在最新版本中添加了对不同环境（如 Jupyter Notebook、Colab）的 CDN 资源自适应支持。请执行 `pip install -U bnlearn` 升级到最新版本，即可修复交互式图表空白的问题。如果仍无效，请检查网络连接或尝试更换浏览器。","https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues\u002F47",{"id":155,"question_zh":156,"answer_zh":157,"source_url":158},25460,"调用 bn.plot 时只弹出警告但没有生成图形，可能是什么原因？","此问题已在后续版本中修复。它通常与绘图后端或依赖库版本冲突有关。请将 bnlearn 更新至最新版本：`pip install -U bnlearn`。此外，相关问题也与 Issue #103 和 PR #71 的修复有关，更新后应能正常生成静态或交互式图形。","https:\u002F\u002Fgithub.com\u002Ferdogant\u002Fbnlearn\u002Fissues\u002F68",[160,165,170,175,180,185,190,195,200,205,210,215,220,225,230,235,240,245,250,255],{"id":161,"version":162,"summary_zh":163,"released_at":164},162776,"0.13.0","* 向 hillclimbsearch 添加了参数 start_dag #120\n\n更多信息请参见 [这里](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FStructure%20learning.html#hillclimbsearch-with-dag)","2026-03-07T09:26:53",{"id":166,"version":167,"summary_zh":168,"released_at":169},162777,"0.12.3","* 修复 pandas 新版本更新的问题，因为 bnlearn 中的一些函数依赖于 _from_records 功能，但该功能已发生变化。","2026-02-21T17:35:31",{"id":171,"version":172,"summary_zh":173,"released_at":174},162778,"0.12.2","适用于使用 Python 3.12 或更高版本时的 joblib 和 pgmpy 的补丁 #119","2025-12-08T18:57:38",{"id":176,"version":177,"summary_zh":178,"released_at":179},162779,"0.12.1","修复 PyArrow 安装问题。","2025-12-04T16:58:50",{"id":181,"version":182,"summary_zh":183,"released_at":184},162780,"0.12.0","* 修复首次初始化后 CPD 未更新的 bug #117 ","2025-07-08T08:57:25",{"id":186,"version":187,"summary_zh":188,"released_at":189},162781,"0.11.1","* 参数学习中的错误修复：在某些边缘情况下，结构得分未能正确计算。\n* pgmpy 版本被锁定在 0.1.25，因为这是最后一个不包含各类大语言模型和 Google AI 相关库的版本。\n* 修复了推理中绘图时出现的警告。","2025-05-05T23:18:22",{"id":191,"version":192,"summary_zh":193,"released_at":194},162782,"0.11.0","**全新版本，包含多项更新！**\n\n* 为 `setgraphviz()` 添加了参数 `verify_certificate`\n* 新增功能，更好地处理条件概率表（CPT）。详情请参阅文档 [这里](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FCreate%20DAG.html)。\n    1. 使用 `make_DAG` 时会自动生成 CPT\n    2. `get_parents` 可从边列表中获取父节点\n    3. `generate_cpt` 可按节点生成 CPT\n    4. `build_cpts_from_structure` 可为整个贝叶斯网络结构生成所有 CPT\n\n* 更新了 NumPy 的文档字符串，并改进了错误信息\n* 更新了依赖项和 `pyproject.toml` 文件\n* 更新了单元测试\n* 代码清理与重构\n\n祝您使用愉快！","2025-05-05T19:22:14",{"id":196,"version":197,"summary_zh":198,"released_at":199},162783,"0.10.4","* 修复离散化中的导入问题。\n* 进行推断后绘制图表。\n* 总结推断结果\n\n```python\nquery = bn.inference.fit(model, variables, evidence, plot=True)\nprint(query.text)\n```","2025-04-28T17:48:44",{"id":201,"version":202,"summary_zh":203,"released_at":204},162784,"0.10.3","* 将 pgmpy 冻结在 0.1.26 版本，因为最新版本 1.0.0 是一个包含大量更改的重大更新。\n* 使用 pyproject.toml 替代 setup.py\n* 清理和重构","2025-04-24T14:42:42",{"id":206,"version":207,"summary_zh":208,"released_at":209},162785,"0.10.2","修复 bug #105","2024-10-23T21:44:04",{"id":211,"version":212,"summary_zh":213,"released_at":214},162786,"0.10.1","Fix for bug \"DBN\" not in config found.","2024-10-23T21:14:26",{"id":216,"version":217,"summary_zh":218,"released_at":219},162787,"0.10.0","The impute functionality has been extended with the MICE method thanks to @Ananyapam7 (issue #81).\r\nIn addition, I also added functionality to impute missing categorical values.\r\n\r\nKey features include:\r\n* Supports K-NN imputation for numeric columns.\r\n* Supports MICE imputation for numeric columns.\r\n* Numeric columns are auto-identified and converted for imputation where necessary.\r\n* Includes options to specify the imputation estimator, number of iterations (max_iter), and verbosity level for logging.\r\n* String\u002Fcategorical columns are imputed.\r\n\r\nCreated a new file impute.py for imputation related functions.\r\nSee examples and more information in the [documentation pages](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fimpute.html).\r\n\r\n","2024-10-20T09:55:04",{"id":221,"version":222,"summary_zh":223,"released_at":224},162788,"0.9.1","* bug fix when using parameter learning","2024-10-15T07:42:11",{"id":226,"version":227,"summary_zh":228,"released_at":229},162789,"0.9.0","* Lingam methods (Direct and ICA) are implemented to model datasets with continuous variables (without discretizing). See docs [here](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FContinuous%20Data.html). #36 #94 \r\n* Plotting is now possible using Graphviz which creates more clear figures. See docs [here](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002FPlot.html#static-plot-graphviz).\r\n* For Constraint-based (PC), CII 9 tests are included and the alpha can be set.\r\n* Parameter showfig and visible is available now for plotting #103 \r\n* Dynamic Bayesian Network (DBN) implemented. #100. See docs [here](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.bnlearn.html#bnlearn.bnlearn.make_DAG) and [here](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fbnlearn.parameter_learning.html#module-bnlearn.parameter_learning).\r\n* Impute functionality implemented in case of missing values. #81  See docs over [here](https:\u002F\u002Ferdogant.github.io\u002Fbnlearn\u002Fpages\u002Fhtml\u002Fimpute.html).\r\n* Updated docstrings and sphinx documentation pages.\r\n* Created a logo! :-)","2024-10-08T18:05:50",{"id":231,"version":232,"summary_zh":233,"released_at":234},162790,"0.8.9","* Fix for issue #98 Where the interactive plot sometimes produced an error. The issue was that nodenames are cleaned in d3blocks but this step was skipped in the interactive plot of bnlearn.","2024-07-22T16:38:53",{"id":236,"version":237,"summary_zh":238,"released_at":239},162791,"0.8.8","* Latest version of pandas is supported again.","2024-05-22T16:03:02",{"id":241,"version":242,"summary_zh":243,"released_at":244},162792,"0.8.7","* Fix for showing the weights in the edges for the static plot","2024-04-12T20:58:41",{"id":246,"version":247,"summary_zh":248,"released_at":249},162793,"0.8.6","* Fix for issue #99 \r\n* Removed d3blocks from setup \u002Frequirements and added it as check when using the interactive plot functionality ","2024-04-09T19:52:20",{"id":251,"version":252,"summary_zh":253,"released_at":254},162794,"0.8.5","* add d3blocks to setup and requirements with minimum version. The wrong version can break the interactive plots.","2024-03-16T14:43:04",{"id":256,"version":257,"summary_zh":258,"released_at":259},162795,"0.8.4","* Fix the issue, sorting the continuous_columns in the correct order when discretizing continuous data @ankh1999 ","2023-11-15T21:51:05"]