[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-interpretml--DiCE":3,"tool-interpretml--DiCE":64},[4,17,27,35,43,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},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,3,"2026-04-05T11:01:52",[13,14,15],"开发框架","图像","Agent","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":23,"last_commit_at":24,"category_tags":25,"status":16},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 真正成长为懂上",138956,2,"2026-04-05T11:33:21",[13,15,26],"语言模型",{"id":28,"name":29,"github_repo":30,"description_zh":31,"stars":32,"difficulty_score":23,"last_commit_at":33,"category_tags":34,"status":16},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 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",107662,"2026-04-03T11:11:01",[13,14,15],{"id":36,"name":37,"github_repo":38,"description_zh":39,"stars":40,"difficulty_score":23,"last_commit_at":41,"category_tags":42,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,26],{"id":44,"name":45,"github_repo":46,"description_zh":47,"stars":48,"difficulty_score":23,"last_commit_at":49,"category_tags":50,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[14,51,52,53,15,54,26,13,55],"数据工具","视频","插件","其他","音频",{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":10,"last_commit_at":62,"category_tags":63,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,"2026-04-04T04:44:48",[15,14,13,26,54],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":80,"owner_twitter":79,"owner_website":81,"owner_url":82,"languages":83,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":23,"env_os":92,"env_gpu":93,"env_ram":93,"env_deps":94,"category_tags":106,"github_topics":107,"view_count":23,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":115,"updated_at":116,"faqs":117,"releases":148},1241,"interpretml\u002FDiCE","DiCE","Generate Diverse Counterfactual Explanations for any machine learning model. ","DiCE 是一个开源工具，用于为任何机器学习模型生成多样化的反事实解释。简单来说，它可以帮助我们理解“如果某些条件发生变化，模型的预测结果会如何改变”。例如，当一个贷款申请被拒绝时，DiCE 可以告诉我们哪些具体因素的调整可能会让结果变成通过。\n\n传统的方法往往只能提供一个单一的解释，而 DiCE 通过生成多个不同的反事实场景，帮助用户更全面地理解模型的决策逻辑。这在金融、医疗、教育等关键领域尤为重要，因为这些领域的决策通常需要透明和可解释性。\n\nDiCE 特别适合研究人员和开发者使用，他们可以利用这个工具深入分析模型行为，或者将其集成到自己的系统中以提升模型的可解释性。对于非技术人员，DiCE 提供了丰富的文档和示例，便于理解和应用。\n\n其独特之处在于，DiCE 不仅关注模型的输出结果，还通过扰动输入特征来生成多种可能的反事实解释，从而让用户更清楚地了解哪些因素真正影响了模型的判断。这种多样化的方式有助于发现潜在的偏见或改进方向。","|PyPiVersion|_ |CondaVersion|_ |MITlicense| |PythonSupport|_ |Downloads|_ \r\n\r\n|BuildStatusTests|_ |BuildStatusNotebooks|_ \r\n\r\n.. |MITlicense| image:: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-blue.svg\r\n.. _MITlicense: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-blue.svg\r\n\r\n.. |PyPiVersion| image:: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fdice-ml\r\n.. _PyPiVersion: https:\u002F\u002Fpypi.org\u002Fproject\u002Fdice-ml\u002F\r\n\r\n.. |Downloads| image:: https:\u002F\u002Fstatic.pepy.tech\u002Fpersonalized-badge\u002Fdice-ml?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads\r\n.. _Downloads: https:\u002F\u002Fpepy.tech\u002Fproject\u002Fdice-ml\r\n\r\n.. |PythonSupport| image:: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fdice-ml\r\n.. _PythonSupport: https:\u002F\u002Fpypi.org\u002Fproject\u002Fdice-ml\u002F\r\n\r\n.. |CondaVersion| image:: https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fdice-ml\u002Fbadges\u002Fversion.svg\r\n.. _CondaVersion: https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fdice-ml\r\n\r\n.. |BuildStatusTests| image:: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fpython-package.yml\u002Fbadge.svg?branch=main\r\n.. _BuildStatusTests: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fpython-package.yml?query=workflow%3A%22Python+package%22\r\n\r\n.. |BuildStatusNotebooks| image:: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fnotebook-tests.yml\u002Fbadge.svg?branch=main\r\n.. _BuildStatusNotebooks: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fnotebook-tests.yml?query=workflow%3A%22Notebook+tests%22\r\n\r\nDiverse Counterfactual Explanations (DiCE) for ML\r\n======================================================================\r\n\r\n*How to explain a machine learning model such that the explanation is truthful to the model and yet interpretable to people?*\r\n\r\n`Ramaravind K. Mothilal \u003Chttps:\u002F\u002Fraam93.github.io\u002F>`_, `Amit Sharma \u003Chttp:\u002F\u002Fwww.amitsharma.in\u002F>`_, `Chenhao Tan \u003Chttps:\u002F\u002Fchenhaot.com\u002F>`_\r\n  \r\n`FAT* '20 paper \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1905.07697>`_ | `Docs \u003Chttps:\u002F\u002Finterpretml.github.io\u002FDiCE\u002F>`_ | `Example Notebooks \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Ftree\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks>`_ | Live Jupyter notebook |Binder|_\r\n\r\n.. |Binder| image:: https:\u002F\u002Fmybinder.org\u002Fbadge_logo.svg\r\n.. _Binder:  https:\u002F\u002Fmybinder.org\u002Fv2\u002Fgh\u002FinterpretML\u002FDiCE\u002Fmaster?filepath=docs\u002Fsource\u002Fnotebooks\r\n\r\n **Blog Post**: `Explanation for ML using diverse counterfactuals \u003Chttps:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fresearch\u002Fblog\u002Fopen-source-library-provides-explanation-for-machine-learning-through-diverse-counterfactuals\u002F>`_\r\n \r\n **Case Studies**: `Towards Data Science \u003Chttps:\u002F\u002Ftowardsdatascience.com\u002Fdice-diverse-counterfactual-explanations-for-hotel-cancellations-762c311b2c64>`_ (Hotel Bookings) | `Analytics Vidhya \u003Chttps:\u002F\u002Fmedium.com\u002Fanalytics-vidhya\u002Fdice-ml-models-with-counterfactual-explanations-for-the-sunk-titanic-30aa035056e0>`_ (Titanic Dataset)\r\n \r\n.. image:: https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fresearch\u002Fuploads\u002Fprod\u002F2020\u002F01\u002FMSR-Amit_1400x788-v3-1blog.gif\r\n  :align: center\r\n  :alt: Visualizing a counterfactual explanation\r\n  \r\nExplanations are critical for machine learning, especially as machine learning-based systems are being used to inform decisions in societally critical domains such as finance, healthcare, education, and criminal justice.\r\nHowever, most explanation methods depend on an approximation of the ML model to\r\ncreate an interpretable explanation. For example,\r\nconsider a person who applied for a loan and was rejected by the loan distribution algorithm of a financial company. Typically, the company may provide an explanation on why the loan was rejected, for example, due to \"poor credit history\". However, such an explanation does not help the person decide *what they should do next* to improve their chances of being approved in the future. Critically, the most important feature may not be enough to flip the decision of the algorithm, and in practice, may not even be changeable such as gender and race.\r\n\r\n\r\nDiCE implements `counterfactual (CF) explanations \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1711.00399>`_  that provide this information by showing feature-perturbed versions of the same person who would have received the loan, e.g., ``you would have received the loan if your income was higher by $10,000``. In other words, it provides \"what-if\" explanations for model output and can be a useful complement to other explanation methods, both for end-users and model developers.\r\n\r\nBarring simple linear models, however, it is difficult to generate CF examples that work for any machine learning model. DiCE is based on `recent research \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1905.07697>`_ that generates CF explanations for any ML model. The core idea is to setup finding such explanations as an optimization problem, similar to finding adversarial examples. The critical difference is that for explanations, we need perturbations that change the output of a machine learning model, but are also diverse and feasible to change. Therefore, DiCE supports generating a set of counterfactual explanations  and has tunable parameters for diversity and proximity of the explanations to the original input. It also supports simple constraints on features to ensure feasibility of the generated counterfactual examples.\r\n\r\n\r\nInstalling DICE\r\n-----------------\r\nDiCE supports Python 3+. The stable version of DiCE is available on `PyPI \u003Chttps:\u002F\u002Fpypi.org\u002Fproject\u002Fdice-ml\u002F>`_.\r\n\r\n.. code:: bash\r\n\r\n    pip install dice-ml\r\n\r\nDiCE is also available on `conda-forge \u003Chttps:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fdice-ml>`_. \r\n\r\n.. code:: bash\r\n\r\n    conda install -c conda-forge dice-ml\r\n\r\nTo install the latest (dev) version of DiCE and its dependencies, clone this repo and run `pip install` from the top-most folder of the repo:\r\n\r\n.. code:: bash\r\n\r\n    pip install -e .\r\n\r\nIf you face any problems, try installing dependencies manually.\r\n\r\n.. code:: bash\r\n\r\n    pip install -r requirements.txt\r\n    # Additional dependendies for deep learning models\r\n    pip install -r requirements-deeplearning.txt\r\n    # For running unit tests\r\n    pip install -r requirements-test.txt\r\n\r\n\r\nGetting started with DiCE\r\n-------------------------\r\nWith DiCE, generating explanations is a simple three-step  process: set up a dataset, train a model, and then invoke DiCE to generate counterfactual examples for any input. DiCE can also work with pre-trained models, with or without their original training data. \r\n\r\n\r\n.. code:: python\r\n\r\n    import dice_ml\r\n    from dice_ml.utils import helpers # helper functions\r\n    from sklearn.model_selection import train_test_split\r\n\r\n    dataset = helpers.load_adult_income_dataset()\r\n    target = dataset[\"income\"] # outcome variable \r\n    train_dataset, test_dataset, _, _ = train_test_split(dataset,\r\n                                                         target,\r\n                                                         test_size=0.2,\r\n                                                         random_state=0,\r\n                                                         stratify=target)\r\n    # Dataset for training an ML model\r\n    d = dice_ml.Data(dataframe=train_dataset,\r\n                     continuous_features=['age', 'hours_per_week'],\r\n                     outcome_name='income')\r\n    \r\n    # Pre-trained ML model\r\n    m = dice_ml.Model(model_path=dice_ml.utils.helpers.get_adult_income_modelpath(),\r\n                      backend='TF2', func=\"ohe-min-max\")\r\n    # DiCE explanation instance\r\n    exp = dice_ml.Dice(d,m)\r\n\r\nFor any given input, we can now generate counterfactual explanations. For\r\nexample, the following input leads to class 0 (low income) and we would like to know what minimal changes would lead to a prediction of 1 (high income).\r\n\r\n.. code:: python\r\n    \r\n    # Generate counterfactual examples\r\n    query_instance = test_dataset.drop(columns=\"income\")[0:1]\r\n    dice_exp = exp.generate_counterfactuals(query_instance, total_CFs=4, desired_class=\"opposite\")\r\n    # Visualize counterfactual explanation\r\n    dice_exp.visualize_as_dataframe()\r\n\r\n.. image:: https:\u002F\u002Fraw.githubusercontent.com\u002Finterpretml\u002FDiCE\u002Fmaster\u002Fdocs\u002F_static\u002Fgetting_started_updated.png \r\n  :width: 400\r\n  :alt: List of counterfactual examples\r\n\r\nYou can save the generated counterfactual examples in the following way.\r\n\r\n.. code:: python\r\n\r\n    # Save generated counterfactual examples to disk\r\n    dice_exp.cf_examples_list[0].final_cfs_df.to_csv(path_or_buf='counterfactuals.csv', index=False)\r\n\r\n\r\nFor more details, check out the `docs\u002Fsource\u002Fnotebooks \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Ftree\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks>`_ folder. Here are some example notebooks:\r\n\r\n* `Getting Started \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_getting_started.ipynb>`_: Generate CF examples for a `sklearn`, `tensorflow` or `pytorch` binary classifier and compute feature importance scores.\r\n* `Explaining Multi-class Classifiers and Regressors\r\n  \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_multiclass_classification_and_regression.ipynb>`_: Generate CF explanations for a multi-class classifier or regressor.\r\n* `Local and Global Feature Importance \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_feature_importances.ipynb>`_: Estimate local and global feature importance scores using generated counterfactuals.\r\n* `Providing Constraints on Counterfactual Generation\r\n  \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_model_agnostic_CFs.ipynb>`_: Specifying which features to vary and their permissible ranges for valid counterfactual examples.\r\n\r\nSupported methods for generating counterfactuals\r\n------------------------------------------------\r\nDiCE can generate counterfactual examples using the following methods.\r\n\r\n**Model-agnostic methods**\r\n\r\n* Randomized sampling \r\n* KD-Tree (for counterfactuals within the training data)\r\n* Genetic algorithm \r\n\r\nSee `model-agnostic notebook\r\n\u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_model_agnostic_CFs.ipynb>`_ for code examples on using these methods.\r\n\r\n**Gradient-based methods**\r\n\r\n* An explicit loss-based method described in `Mothilal et al. (2020) \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1905.07697>`_ (Default for deep learning models).\r\n* A Variational AutoEncoder (VAE)-based method described in `Mahajan et al. (2019) \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1912.03277>`_ (see the BaseVAE `notebook \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fnotebooks\u002FDiCE_getting_started_feasible.ipynb>`_).\r\n\r\nThe last two methods require a differentiable model, such as a neural network. If you are interested in a specific method, do raise an issue `here \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues>`_.\r\n\r\nSupported use-cases\r\n-------------------\r\n**Data**\r\n\r\nDiCE does not need access to the full dataset. It only requires metadata properties for each feature (min, max for continuous features and levels for categorical features). Thus, for sensitive data, the dataset can be provided as:\r\n\r\n.. code:: python\r\n\r\n    d = data.Data(features={\r\n                       'age':[17, 90],\r\n                       'workclass': ['Government', 'Other\u002FUnknown', 'Private', 'Self-Employed'],\r\n                       'education': ['Assoc', 'Bachelors', 'Doctorate', 'HS-grad', 'Masters', 'Prof-school', 'School', 'Some-college'],\r\n                       'marital_status': ['Divorced', 'Married', 'Separated', 'Single', 'Widowed'],\r\n                       'occupation':['Blue-Collar', 'Other\u002FUnknown', 'Professional', 'Sales', 'Service', 'White-Collar'],\r\n                       'race': ['Other', 'White'],\r\n                       'gender':['Female', 'Male'],\r\n                       'hours_per_week': [1, 99]},\r\n             outcome_name='income')\r\n\r\n**Model**\r\n\r\nWe support pre-trained models as well as training a model. Here's a simple example using Tensorflow. \r\n\r\n.. code:: python\r\n\r\n    sess = tf.InteractiveSession()\r\n    # Generating train and test data\r\n    train, _ = d.split_data(d.normalize_data(d.one_hot_encoded_data))\r\n    X_train = train.loc[:, train.columns != 'income']\r\n    y_train = train.loc[:, train.columns == 'income']\r\n    # Fitting a dense neural network model\r\n    ann_model = keras.Sequential()\r\n    ann_model.add(keras.layers.Dense(20, input_shape=(X_train.shape[1],), kernel_regularizer=keras.regularizers.l1(0.001), activation=tf.nn.relu))\r\n    ann_model.add(keras.layers.Dense(1, activation=tf.nn.sigmoid))\r\n    ann_model.compile(loss='binary_crossentropy', optimizer=tf.keras.optimizers.Adam(0.01), metrics=['accuracy'])\r\n    ann_model.fit(X_train, y_train, validation_split=0.20, epochs=100, verbose=0, class_weight={0:1,1:2})\r\n\r\n    # Generate the DiCE model for explanation\r\n    m = model.Model(model=ann_model)\r\n\r\nCheck out the `Getting Started \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_getting_started.ipynb>`_ notebook to see code examples on using DiCE with sklearn and PyTorch models.\r\n\r\n**Explanations**\r\n\r\nWe visualize explanations through a table highlighting the change in features. We plan to support an English language explanation too!\r\n\r\nFeasibility of counterfactual explanations\r\n-------------------------------------------\r\nWe acknowledge that not all counterfactual explanations may be feasible for a\r\nuser. In general, counterfactuals closer to an individual's profile will be\r\nmore feasible. Diversity is also important to help an individual choose between\r\nmultiple possible options.\r\n\r\nDiCE provides tunable parameters for diversity and proximity to generate\r\ndifferent kinds of explanations.\r\n\r\n.. code:: python\r\n\r\n    dice_exp = exp.generate_counterfactuals(query_instance,\r\n                    total_CFs=4, desired_class=\"opposite\",\r\n                    proximity_weight=1.5, diversity_weight=1.0)\r\n\r\nAdditionally, it may be the case that some features are harder to change than\r\nothers (e.g., education level is harder to change than working hours per week). DiCE allows input of relative difficulty in changing a feature through specifying *feature weights*. A higher feature weight means that the feature is harder to change than others. For instance, one way is to use the mean absolute deviation from the median as a measure of relative difficulty of changing a continuous feature. By default, DiCE computes this internally and divides the distance between continuous features by the MAD of the feature's values in the training set. We can also assign different values through the *feature_weights* parameter. \r\n\r\n.. code:: python\r\n\r\n    # assigning new weights\r\n    feature_weights = {'age': 10, 'hours_per_week': 5}\r\n    # Now generating explanations using the new feature weights\r\n    dice_exp = exp.generate_counterfactuals(query_instance,\r\n                    total_CFs=4, desired_class=\"opposite\",\r\n                    feature_weights=feature_weights)\r\n\r\nFinally, some features are impossible to change such as one's age or race. Therefore, DiCE also allows inputting a\r\nlist of features to vary.\r\n\r\n.. code:: python\r\n\r\n    dice_exp = exp.generate_counterfactuals(query_instance,\r\n                    total_CFs=4, desired_class=\"opposite\",\r\n                    features_to_vary=['age','workclass','education','occupation','hours_per_week'])\r\n\r\nIt also supports simple constraints on\r\nfeatures that reflect practical constraints (e.g., working hours per week\r\nshould be between 10 and 50 using the ``permitted_range`` parameter).\r\n\r\nFor more details, check out `this \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_model_agnostic_CFs.ipynb>`_ notebook.\r\n\r\nThe promise of counterfactual explanations\r\n-------------------------------------------\r\nBeing truthful to the model, counterfactual explanations can be useful to all stakeholders for a decision made by a machine learning model that makes decisions.\r\n\r\n* **Decision subjects**: Counterfactual explanations can be used to explore actionable recourse for a person based on a decision received by a ML model. DiCE shows decision outcomes with *actionable* alternative profiles, to help people understand what they could have done to change their model outcome.\r\n\r\n* **ML model developers**: Counterfactual explanations are also useful for model developers to debug their model for potential problems. DiCE can be used to show CF explanations for a selection of inputs that can uncover if there are any problematic (in)dependences on some features (e.g., for 95% of inputs, changing features X and Y change the outcome, but not for the other 5%). We aim to support aggregate metrics to help developers debug ML models.\r\n\r\n* **Decision makers**: Counterfactual explanations may be useful to\r\n  decision-makers such as doctors or judges who may use ML models to make decisions. For a particular individual, DiCE allows probing the ML model to see the possible changes that lead to a different ML outcome, thus enabling decision-makers to assess their trust in the prediction.\r\n\r\n* **Decision evaluators**: Finally, counterfactual explanations can be useful\r\n  to decision evaluators who may be interested in fairness or other desirable\r\n  properties of an ML model. We plan to add support for this in the future.\r\n\r\n\r\nRoadmap\r\n-------\r\nIdeally, counterfactual explanations should balance between a wide range of suggested changes (*diversity*), and the relative ease of adopting those changes (*proximity* to the original input), and also follow the causal laws of the world, e.g., one can hardly lower their educational degree or change their race.\r\n\r\nWe are working on adding the following features to DiCE:\r\n\r\n* Support for using DiCE for debugging machine learning models\r\n* Constructed English phrases (e.g., ``desired outcome if feature was changed``) and other ways to output the counterfactual examples\r\n* Evaluating feature attribution methods like LIME and SHAP on necessity and sufficiency metrics using counterfactuals (see `this paper \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F2011.04917>`_)\r\n* Support for Bayesian optimization and other algorithms for generating counterfactual explanations\r\n* Better feasibility constraints for counterfactual generation \r\n\r\nCiting\r\n-------\r\nIf you find DiCE useful for your research work, please cite it as follows.\r\n\r\nRamaravind K. Mothilal, Amit Sharma, and Chenhao Tan (2020). **Explaining machine learning classifiers through diverse counterfactual explanations**. *Proceedings of the 2020 Conference on Fairness, Accountability, and Transparency*. \r\n\r\nBibtex::\r\n\r\n\t@inproceedings{mothilal2020dice,\r\n  \t\ttitle={Explaining machine learning classifiers through diverse counterfactual explanations},\r\n  \t\tauthor={Mothilal, Ramaravind K and Sharma, Amit and Tan, Chenhao},\r\n  \t\tbooktitle={Proceedings of the 2020 Conference on Fairness, Accountability, and Transparency},\r\n  \t\tpages={607--617},\r\n  \t\tyear={2020}\r\n\t}\r\n\r\n\r\nContributing\r\n------------\r\n\r\nThis project welcomes contributions and suggestions.  Most contributions require you to agree to a\r\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\r\nthe rights to use your contribution. For details, visit https:\u002F\u002Fcla.microsoft.com.\r\n\r\nWhen you submit a pull request, a CLA-bot will automatically determine whether you need to provide\r\na CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions\r\nprovided by the bot. You will only need to do this once across all repos using our CLA.\r\n\r\nThis project has adopted the `Microsoft Open Source Code of Conduct \u003Chttps:\u002F\u002Fopensource.microsoft.com\u002Fcodeofconduct\u002F>`_.\r\nFor more information see the `Code of Conduct FAQ \u003Chttps:\u002F\u002Fopensource.microsoft.com\u002Fcodeofconduct\u002Ffaq\u002F>`_ or\r\ncontact `opencode@microsoft.com \u003Cmailto:opencode@microsoft.com>`_ with any additional questions or comments.\r\n","|PyPiVersion|_ |CondaVersion|_ |MITlicense| |PythonSupport|_ |Downloads|_ \n\n|BuildStatusTests|_ |BuildStatusNotebooks|_ \n\n.. |MITlicense| image:: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-blue.svg\n.. _MITlicense: https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-blue.svg\n\n.. |PyPiVersion| image:: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fv\u002Fdice-ml\n.. _PyPiVersion: https:\u002F\u002Fpypi.org\u002Fproject\u002Fdice-ml\u002F\n\n.. |Downloads| image:: https:\u002F\u002Fstatic.pepy.tech\u002Fpersonalized-badge\u002Fdice-ml?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads\n.. _Downloads: https:\u002F\u002Fpepy.tech\u002Fproject\u002Fdice-ml\n\n.. |PythonSupport| image:: https:\u002F\u002Fimg.shields.io\u002Fpypi\u002Fpyversions\u002Fdice-ml\n.. _PythonSupport: https:\u002F\u002Fpypi.org\u002Fproject\u002Fdice-ml\u002F\n\n.. |CondaVersion| image:: https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fdice-ml\u002Fbadges\u002Fversion.svg\n.. _CondaVersion: https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fdice-ml\n\n.. |BuildStatusTests| image:: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fpython-package.yml\u002Fbadge.svg?branch=main\n.. _BuildStatusTests: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fpython-package.yml?query=workflow%3A%22Python+package%22\n\n.. |BuildStatusNotebooks| image:: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fnotebook-tests.yml\u002Fbadge.svg?branch=main\n.. _BuildStatusNotebooks: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Factions\u002Fworkflows\u002Fnotebook-tests.yml?query=workflow%3A%22Notebook+tests%22\n\n用于机器学习的多样化反事实解释（DiCE）\n======================================================================\n\n*如何解释一个机器学习模型，使其既忠实于模型本身，又易于人类理解？*\n\n`Ramaravind K. Mothilal \u003Chttps:\u002F\u002Fraam93.github.io\u002F>`_, `Amit Sharma \u003Chttp:\u002F\u002Fwww.amitsharma.in\u002F>`_, `Chenhao Tan \u003Chttps:\u002F\u002Fchenhaot.com\u002F>`\n  \n`FAT* '20论文 \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1905.07697>`_ | `文档 \u003Chttps:\u002F\u002Finterpretml.github.io\u002FDiCE\u002F>`_ | `示例笔记本 \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Ftree\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks>`_ | 实时Jupyter笔记本 |Binder|_\n\n.. |Binder| image:: https:\u002F\u002Fmybinder.org\u002Fbadge_logo.svg\n.. _Binder:  https:\u002F\u002Fmybinder.org\u002Fv2\u002Fgh\u002FinterpretML\u002FDiCE\u002Fmaster?filepath=docs\u002Fsource\u002Fnotebooks\n\n**博客文章**: `利用多样化反事实进行机器学习解释 \u003Chttps:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fresearch\u002Fblog\u002Fopen-source-library-provides-explanation-for-machine-learning-through-diverse-counterfactuals\u002F>`\n \n**案例研究**: `Towards Data Science \u003Chttps:\u002F\u002Ftowardsdatascience.com\u002Fdice-diverse-counterfactual-explanations-for-hotel-cancellations-762c311b2c64>`_ (酒店预订) | `Analytics Vidhya \u003Chttps:\u002F\u002Fmedium.com\u002Fanalytics-vidhya\u002Fdice-ml-models-with-counterfactual-explanations-for-the-sunk-titanic-30aa035056e0>`_ (泰坦尼克号数据集)\n \n.. image:: https:\u002F\u002Fwww.microsoft.com\u002Fen-us\u002Fresearch\u002Fuploads\u002Fprod\u002F2020\u002F01\u002FMSR-Amit_1400x788-v3-1blog.gif\n  :align: center\n  :alt: 可视化反事实解释\n  \n解释对于机器学习至关重要，尤其是在金融、医疗、教育和刑事司法等关乎社会重大利益的领域中，基于机器学习的系统正被广泛用于辅助决策。\n然而，大多数解释方法都依赖于对机器学习模型的近似来生成可解释的解释。例如，\n假设某人申请了一笔贷款，却被一家金融公司的贷款发放算法拒绝了。通常，该公司会给出一个关于贷款被拒的原因的解释，比如“信用记录不佳”。然而，这样的解释并不能帮助申请人决定*下一步该怎么做*才能提高未来获批的可能性。更关键的是，最重要的特征可能根本不足以改变算法的决策，而且在实际中，有些特征甚至无法改变，比如性别和种族。\n\n\nDiCE实现了`反事实（CF）解释 \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1711.00399>`_，通过展示同一人的特征扰动版本来提供这类信息，这些版本的人本应获得贷款，例如：“如果你的收入再高1万美元，你就能获得贷款”。换句话说，它为模型输出提供了“如果……会怎样”的解释，并且可以作为其他解释方法的有效补充，无论是对终端用户还是对模型开发者而言。\n\n不过，除了简单的线性模型外，要为任何机器学习模型生成有效的CF示例都相当困难。DiCE基于`最新研究 \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1905.07697>`_，能够为任何机器学习模型生成CF解释。其核心思想是将寻找此类解释的问题转化为一个优化问题，类似于寻找对抗样本。关键区别在于，对于解释而言，我们需要的扰动既要能改变机器学习模型的输出，又要具有多样性且在现实中切实可行。因此，DiCE支持生成一组反事实解释，并且具备可调参数，用于控制解释的多样性和与原始输入的接近程度。此外，它还支持对特征施加简单约束，以确保生成的反事实示例切实可行。\n\n\n安装DICE\n-----------------\nDiCE支持Python 3及以上版本。DiCE的稳定版已在`PyPI \u003Chttps:\u002F\u002Fpypi.org\u002Fproject\u002Fdice-ml\u002F>`_上发布。\n\n.. code:: bash\n\n    pip install dice-ml\n\nDiCE也在`conda-forge \u003Chttps:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fdice-ml>`_上可用。\n\n.. code:: bash\n\n    conda install -c conda-forge dice-ml\n\n要安装DiCE的最新（开发）版本及其依赖项，需克隆此仓库并在仓库的最顶层文件夹中运行`pip install`：\n\n.. code:: bash\n\n    pip install -e .\n\n如遇任何问题，可尝试手动安装依赖项。\n\n.. code:: bash\n\n    pip install -r requirements.txt\n    # 针对深度学习模型的额外依赖\n    pip install -r requirements-deeplearning.txt\n    # 运行单元测试所需\n    pip install -r requirements-test.txt\n\n\n开始使用DiCE\n-------------------------\n借助DiCE，生成解释只需三个简单步骤：准备数据集、训练模型，然后调用DiCE为任意输入生成反事实示例。DiCE也可以与预训练模型配合使用，无论是否拥有原始训练数据。\n\n\n.. code:: python\n\n    import dice_ml\n    from dice_ml.utils import helpers # 辅助函数\n    from sklearn.model_selection import train_test_split\n\n    数据集 = helpers.load_adult_income_dataset()\n    目标变量 = 数据集[\"income\"] # 结果变量 \n    训练集、测试集、以及剩余部分，通过train_test_split分割数据集，\n                                                         目标变量，\n                                                         测试集占比20%，\n                                                         随机种子0，\n                                                         按目标变量分层抽样\n    # 用于训练机器学习模型的数据集\n    d = dice_ml.Data(dataframe=train_dataset,\n                     连续特征['年龄', '每周工作小时数'],\n                     结果名称='收入')\n    \n    # 预训练的机器学习模型\n    m = dice_ml.Model(model_path=dice_ml.utils.helpers.get_adult_income_modelpath(),\n                      后端='TF2', 函数=\"ohe-min-max\")\n    # DiCE解释实例\n    exp = dice_ml.Dice(d,m)\n\n对于任意给定的输入，我们现在可以生成反事实解释。例如，\n以下输入会导致类别0（低收入），而我们想知道哪些最小的变化能够使预测结果变为1（高收入）。\n\n\n.. code:: python\n    \n    # 生成反事实示例\n    查询实例 = test_dataset.drop(columns=\"收入\")[0:1]\n    dice_exp = exp.generate_counterfactuals(query_instance, total_CFs=4, desired_class=\"opposite\")\n    # 可视化反事实解释\n    dice_exp.visualize_as_dataframe()\n\n.. image:: https:\u002F\u002Fraw.githubusercontent.com\u002Finterpretml\u002FDiCE\u002Fmaster\u002Fdocs\u002F_static\u002Fgetting_started_updated.png \n  :width: 400\n  :alt: 反事实示例列表\n\n您可以通过以下方式保存生成的反事实示例。\n\n.. code:: python\n\n    # 将生成的反事实示例保存到磁盘\n    dice_exp.cf_examples_list[0].final_cfs_df.to_csv(path_or_buf='counterfactuals.csv', index=False)\n\n\n更多详情，请参阅`docs\u002Fsource\u002Fnotebooks \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Ftree\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks>`_文件夹。这里有一些示例笔记本：\n\n* `入门指南 \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_getting_started.ipynb>`_: 为`sklearn`、`tensorflow`或`pytorch`二分类器生成CF示例，并计算特征重要性得分。\n* `解释多类分类器和回归器\n  \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_multiclass_classification_and_regression.ipynb>`_: 为多类分类器或回归器生成CF解释。\n* `局部与全局特征重要性 \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_feature_importances.ipynb>`_: 利用生成的反事实估计局部和全局特征重要性得分。\n* `为反事实生成设定约束\n  \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_model_agnostic_CFs.ipynb>`_: 指定需要变化的特征及其允许范围，以确保生成的反事实示例有效。\n\n支持的反事实生成方法\n------------------------------------------------\nDiCE可以使用以下方法生成反事实示例。\n\n**与模型无关的方法**\n\n* 随机采样 \n* KD树（用于训练数据内的反事实）\n* 遗传算法 \n\n请参阅`与模型无关的笔记本\n\u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_model_agnostic_CFs.ipynb>`_，了解如何使用这些方法的代码示例。\n\n**基于梯度的方法**\n\n* 在`Mothilal等人（2020年） \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1905.07697>`_中描述的显式损失驱动方法（深度学习模型的默认方法）。\n* 在`Mahajan等人（2019年） \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F1912.03277>`_中描述的变分自编码器（VAE）方法（参见BaseVAE的`笔记本 \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fnotebooks\u002FDiCE_getting_started_feasible.ipynb>`_）。\n\n后两种方法需要可微分的模型，例如神经网络。如果您对某种特定方法感兴趣，请在此处提交问题`here \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues>`_。\n\n支持的使用场景\n-------------------\n**数据**\n\nDiCE并不需要访问完整的数据集。它只需要每个特征的元数据属性（连续特征的最小值、最大值，以及分类特征的取值水平）。因此，对于敏感数据，可以这样提供数据集：\n\n.. code:: python\n\n    d = data.Data(features={\n                       '年龄':[17, 90],\n                       '工作单位': ['政府', '其他\u002F未知', '私人', '个体经营'],\n                       '教育': ['协会', '学士', '博士', '高中毕业', '硕士', '专业学校', '学校', '一些大学'],\n                       '婚姻状况': ['离婚', '已婚', '分居', '单身', '丧偶'],\n                       '职业':['蓝领', '其他\u002F未知', '专业人士', '销售', '服务', '白领'],\n                       '种族': ['其他', '白人'],\n                       '性别':['女性', '男性'],\n                       '每周工作小时数': [1, 99]},\n             结果名称='收入')\n\n**模型**\n\n我们既支持预训练模型，也支持训练新模型。这里有一个使用Tensorflow的简单示例。\n\n.. code:: python\n\n    sess = tf.InteractiveSession()\n    # 生成训练和测试数据\n    训练集，_ = d.split_data(d.normalize_data(d.one_hot_encoded_data))\n    X_train = train.loc[:, train.columns != '收入']\n    y_train = train.loc[:, train.columns == '收入']\n    # 拟合一个密集型神经网络模型\n    ann_model = keras.Sequential()\n    ann_model.add(keras.layers.Dense(20, input_shape=(X_train.shape[1],), kernel_regularizer=keras.regularizers.l1(0.001), activation=tf.nn.relu))\n    ann_model.add(keras.layers.Dense(1, activation=tf.nn.sigmoid))\n    ann_model.compile(loss='binary_crossentropy', optimizer=tf.keras.optimizers.Adam(0.01), metrics=['accuracy'])\n    ann_model.fit(X_train, y_train, validation_split=0.20, epochs=100, verbose=0, class_weight={0:1,1:2})\n\n    # 生成用于解释的DiCE模型\n    m = model.Model(model=ann_model)\n\n请参阅`入门指南 \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_getting_started.ipynb>`_笔记本，查看使用DiCE结合sklearn和PyTorch模型的代码示例。\n\n**解释**\n\n我们通过一张表格来可视化解释，突出显示特征的变化。我们还计划支持英文解释！ \n\n反事实解释的可行性\n-------------------------------------------\n我们承认，并非所有反事实解释对用户来说都是可行的。一般来说，越接近个人特征的反事实就越容易实现。同时，多样性也很重要，可以帮助个人在多个可能选项之间做出选择。\n\nDiCE提供了可调参数，用于控制多样性和与原始输入的接近程度，从而生成不同类型的解释。\n\n.. code:: python\n\n    dice_exp = exp.generate_counterfactuals(query_instance,\n                    total_CFs=4, desired_class=\"opposite\",\n                    proximity_weight=1.5, diversity_weight=1.0)\n\n此外，某些特征可能比其他特征更难改变（例如，教育程度比每周工作小时数更难改变）。DiCE允许通过指定*特征权重*来输入特征改变的相对难度。较高的特征权重意味着该特征比其他特征更难改变。例如，一种方法是使用与中位数的平均绝对偏差作为衡量连续特征改变相对难度的指标。默认情况下，DiCE会在内部计算这一指标，并将连续特征之间的距离除以该特征在训练集中数值的MAD。我们也可以通过*feature_weights*参数赋予不同的值。\n\n.. code:: python\n\n    # 赋予新的权重\n    feature_weights = {'年龄': 10, '每周工作小时数': 5}\n    # 现在使用新的特征权重生成解释\n    dice_exp = exp.generate_counterfactuals(query_instance,\n                    total_CFs=4, desired_class=\"opposite\",\n                    feature_weights=feature_weights)\n\n最后，有些特征是无法改变的，比如年龄或种族。因此，DiCE也允许输入需要变化的特征列表。\n\n.. code:: python\n\n    dice_exp = exp.generate_counterfactuals(query_instance,\n                    total_CFs=4, desired_class=\"opposite\",\n                    features_to_vary=['年龄','工作单位','教育','职业','每周工作小时数'])\n\n它还支持对特征施加简单的约束，以反映实际限制（例如，每周工作小时数应在10至50之间，可通过``permitted_range``参数设置）。\n\n更多详情，请参阅`this \u003Chttps:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fblob\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks\u002FDiCE_model_agnostic_CFs.ipynb>`_笔记本。\n\n反事实解释的承诺\n-------------------------------------------\n反事实解释忠实于模型，对于因机器学习模型作出的决策，对所有利益相关者都可能很有用。\n\n* **决策对象**：反事实解释可用于探索针对某人因机器学习模型作出的决策所采取的可行补救措施。DiCE展示了带有*可操作*替代特征配置的决策结果，以帮助人们了解自己原本可以做些什么来改变模型的结果。\n\n* **机器学习模型开发者**：反事实解释也有助于模型开发者调试模型，查找潜在问题。DiCE可用于为选定的输入生成CF解释，从而揭示某些特征是否存在有问题的（不）独立性（例如，对于95%的输入，改变特征X和Y会改变结果，但对另外5%则不然）。我们旨在支持汇总指标，以帮助开发者调试机器学习模型。\n\n* **决策者**：反事实解释可能对诸如医生或法官之类的决策者有用，他们可能会使用机器学习模型作出决策。对于特定个人，DiCE允许深入探究机器学习模型，查看可能导致不同模型结果的可能变化，从而使决策者能够评估自己对预测的信任程度。\n\n* **决策评估者**：最后，反事实解释也可能对决策评估者有用，他们可能关注机器学习模型的公平性或其他理想特性。我们计划在未来支持这一功能。\n\n\n路线图\n-------\n理想情况下，反事实解释应在建议的广泛变化范围（*多样性*）与采纳这些变化的相对容易程度（*与原始输入的接近程度*）之间取得平衡，并且还要遵循世界的因果规律，例如，一个人很难降低自己的教育程度或改变自己的种族。\n\n我们正在努力为DiCE添加以下功能：\n\n* 支持使用DiCE调试机器学习模型\n* 构建英文短语（例如，“如果改变了特征，就会得到期望的结果”）以及其他输出反事实示例的方式\n* 使用反事实评估LIME和SHAP等特征归因方法的必要性和充分性指标（参见`this paper \u003Chttps:\u002F\u002Farxiv.org\u002Fabs\u002F2011.04917>`_）\n* 支持贝叶斯优化及其他算法生成反事实解释\n* 更好的反事实生成可行性约束\n\n引用\n-------\n如果您发现DiCE对您的研究工作有帮助，请按如下方式引用。\n\nRamaravind K. Mothilal、Amit Sharma和Chenhao Tan（2020年）。**通过多样化反事实解释来解释机器学习分类器**。*2020年公平、问责与透明度会议论文集*。\n\nBibtex::\n\n\t@inproceedings{mothilal2020dice,\n  \t\ttitle={通过多样化反事实解释来解释机器学习分类器},\n  \t\tauthor={Mothilal, Ramaravind K 和 Sharma, Amit 和 Tan, Chenhao},\n  \t\tbooktitle={2020年公平、问责与透明度会议论文集},\n  \t\tpages={607--617},\n  \t\tyear={2020}\n\t}\n\n\n贡献\n------------\n\n本项目欢迎贡献与建议。大多数贡献都需要您同意一份《贡献者许可协议》（CLA），声明您有权并确实授予我们使用您贡献的权利。详情请访问https:\u002F\u002Fcla.microsoft.com。\n\n当您提交拉取请求时，CLA机器人会自动判断您是否需要提供CLA，并相应地标注PR（例如，添加标签、留言）。您只需按照机器人提供的指示操作即可。在整个使用我们CLA的项目中，您只需完成一次即可。\n\n本项目已采用`微软开源行为准则 \u003Chttps:\u002F\u002Fopensource.microsoft.com\u002Fcodeofconduct\u002F>`_。\n更多信息请参阅`行为准则常见问题 \u003Chttps:\u002F\u002Fopensource.microsoft.com\u002Fcodeofconduct\u002Ffaq\u002F>`_，或如有任何其他问题或意见，请联系`opencode@microsoft.com \u003Cmailto:opencode@microsoft.com>`_。","# DiCE 快速上手指南\n\n## 环境准备\n\n- **系统要求**：支持 Python 3.x 及以上版本\n- **前置依赖**：\n  - Python 3.x\n  - pip 或 conda（推荐使用国内镜像源加速安装）\n\n---\n\n## 安装步骤\n\n### 使用 pip 安装（推荐）\n\n```bash\npip install dice-ml\n```\n\n如需使用国内镜像源，可添加 `-i` 参数：\n\n```bash\npip install dice-ml -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n### 使用 conda 安装\n\n```bash\nconda install -c conda-forge dice-ml\n```\n\n### 安装开发版（从源码安装）\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE.git\ncd DiCE\npip install -e .\n```\n\n如果遇到依赖问题，可以手动安装依赖包：\n\n```bash\npip install -r requirements.txt\npip install -r requirements-deeplearning.txt\n```\n\n---\n\n## 基本使用\n\n以下是一个最简单的使用示例，展示如何生成反事实解释。\n\n### 步骤一：导入库并加载数据\n\n```python\nimport dice_ml\nfrom dice_ml.utils import helpers\nfrom sklearn.model_selection import train_test_split\n\ndataset = helpers.load_adult_income_dataset()\ntarget = dataset[\"income\"]\ntrain_dataset, test_dataset, _, _ = train_test_split(dataset,\n                                                     target,\n                                                     test_size=0.2,\n                                                     random_state=0,\n                                                     stratify=target)\n```\n\n### 步骤二：初始化数据和模型\n\n```python\nd = dice_ml.Data(dataframe=train_dataset,\n                 continuous_features=['age', 'hours_per_week'],\n                 outcome_name='income')\n\nm = dice_ml.Model(model_path=dice_ml.utils.helpers.get_adult_income_modelpath(),\n                  backend='TF2', func=\"ohe-min-max\")\n\nexp = dice_ml.Dice(d, m)\n```\n\n### 步骤三：生成反事实解释\n\n```python\nquery_instance = test_dataset.drop(columns=\"income\")[0:1]\ndice_exp = exp.generate_counterfactuals(query_instance, total_CFs=4, desired_class=\"opposite\")\ndice_exp.visualize_as_dataframe()\n```\n\n### 步骤四：保存结果\n\n```python\ndice_exp.cf_examples_list[0].final_cfs_df.to_csv(path_or_buf='counterfactuals.csv', index=False)\n```\n\n---\n\n通过以上步骤，你可以快速使用 DiCE 工具为机器学习模型生成多样化的反事实解释。更多示例和高级用法，请参考项目文档中的 [Notebooks](https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Ftree\u002Fmaster\u002Fdocs\u002Fsource\u002Fnotebooks)。","某银行信贷部门正在使用一个基于机器学习的自动化贷款审批系统，负责评估客户申请并决定是否批准贷款。然而，当客户被拒绝时，系统仅提供一个简短的解释，如“信用记录不佳”，但无法给出具体的改进建议。\n\n### 没有 DiCE 时\n- 客户收到的解释过于笼统，无法明确知道如何改进以提高未来申请的成功率。\n- 银行难以向客户说明哪些具体因素影响了决策，导致客户对系统的公平性和透明度产生质疑。\n- 无法识别哪些特征是可修改的（如收入、负债），哪些是不可更改的（如性别、种族），从而影响客户体验和信任。\n- 缺乏多样化的解释方式，使得同一类客户可能得到相似的反馈，缺乏个性化指导。\n- 难以验证模型的决策逻辑是否合理，增加模型审计和合规风险。\n\n### 使用 DiCE 后\n- 客户可以获取多种具体的反事实解释，例如：“若您的月收入提高至1.5万元，或负债率降低至30%，则贷款申请将更有可能被批准。”\n- 银行能够清晰展示影响决策的关键因素，并区分可调整与不可调整的变量，提升客户对系统的理解和信任。\n- 提供多样化的解释路径，使不同背景的客户都能获得适合自身情况的建议，增强个性化服务体验。\n- 帮助银行验证模型的可解释性，确保其符合监管要求，减少潜在的法律和合规风险。\n- 支持模型开发者深入分析模型行为，优化模型设计，提升整体决策质量。\n\nDiCE 通过生成多样化的反事实解释，显著提升了机器学习模型在金融场景中的透明度与用户满意度。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Finterpretml_DiCE_9f91dbc2.png","interpretml","InterpretML","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Finterpretml_e5fa3404.png","If a tree fell in your random forest, would anyone notice?",null,"interpret@microsoft.com","https:\u002F\u002Finterpret.ml","https:\u002F\u002Fgithub.com\u002Finterpretml",[84],{"name":85,"color":86,"percentage":87},"Python","#3572A5",100,1507,226,"2026-04-04T14:05:15","MIT","Linux, macOS, Windows","未说明",{"notes":95,"python":96,"dependencies":97},"DiCE 支持通过 pip 或 conda 安装，安装时需确保已正确配置 Python 环境。对于深度学习模型，需要额外安装 requirements-deeplearning.txt 中的依赖项。","3+",[98,99,100,101,102,103,104,105],"scikit-learn","pandas","numpy","tensorflow","pytorch","matplotlib","seaborn","scipy",[13],[108,109,110,111,112,113,114],"counterfactual-explanations","explainable-ml","xai","interpretable-machine-learning","deep-learning","machine-learning","explainable-ai","2026-03-27T02:49:30.150509","2026-04-06T05:16:08.024924",[118,123,128,133,138,143],{"id":119,"question_zh":120,"answer_zh":121,"source_url":122},5646,"如何解决使用 DiCE 时出现的 'IndexError' 错误？","当使用 DiCE 生成反事实时，如果数据中没有分类特征或传递方式不正确，可能会引发 IndexError。确保在创建 dice_ml.Data 对象时，将所有连续特征（包括目标变量）包含在 continuous_features 参数中，并检查 query_instances 是否与训练数据一致。","https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues\u002F168",{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},5647,"如何提高生成的反事实质量？","生成的反事实可能不符合预期，例如在员工流失预测任务中，反事实反而降低了满意度分数。建议检查参数设置，如 proximity_weight 仅适用于 'genetic' 方法，而不是 'random' 或 'kdtree'。此外，确保数据预处理和模型配置正确。","https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues\u002F244",{"id":129,"question_zh":130,"answer_zh":131,"source_url":132},5648,"如何解决 'Negative dimensions are not allowed' 错误？","该错误通常发生在使用遗传算法时，total_CFs 参数大于 population_size。应确保 population_size 是 total_CFs 的倍数，或者通过 PR #205 中的修复来避免此问题。","https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues\u002F192",{"id":134,"question_zh":135,"answer_zh":136,"source_url":137},5649,"DiCE 库是否还在维护？","DiCE 项目仍在维护中，最新版本 v0.12 已发布，并计划移除对 TensorFlow 1.x 的依赖。开发者欢迎社区贡献，以支持新版本的 pandas、numpy 等库。","https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues\u002F454",{"id":139,"question_zh":140,"answer_zh":141,"source_url":142},5650,"如何正确使用训练数据和测试数据进行反事实生成？","DiCE 的 Data 接口需要明确区分训练数据和测试数据。在初始化 dice_ml.Data 时，应传入训练数据集，而用于生成反事实的查询实例应来自测试数据集或独立数据集。","https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues\u002F189",{"id":144,"question_zh":145,"answer_zh":146,"source_url":147},5651,"如何解决 'DataFrame.dtypes for data must be int, float or bool' 错误？","即使数据是浮点类型，也可能因字段名称或数据格式问题导致错误。可以尝试将所有数值型特征放入 continuous_features 参数中，或者检查数据类型是否符合要求。","https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fissues\u002F290",[149,154,159,164,169,174,179,184,189,194,199,204,209],{"id":150,"version":151,"summary_zh":152,"released_at":153},105285,"v0.12","## What's Changed\r\n\r\n* Xgboost interface by @lldartsll in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F452\r\n* Bug fixes and more robust tests \r\n* Enable test case `test_columns_out_of_order` and other code changes by @gaugup \r\n* Add newer python versions to builds by @gaugup in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F449\r\n\r\n## New Contributors\r\n* @lldartsll made their first contribution in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F452\r\n* @BogdanTurbal made their first contribution in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F450\r\n* @asendotsinski made their first contribution in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F415\r\n* @CloseChoice made their first contribution in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F455\r\n\r\nA big thank you to all the contributors!\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fcompare\u002Fv0.11...v0.12","2025-07-13T17:34:53",{"id":155,"version":156,"summary_zh":157,"released_at":158},105286,"v0.11","* Ensure same type for CF output and input features\r\n* Return original class instead of encoded class in CFs\r\n* Better error checking for input query instance\r\n* Dynamic creation of datasets for testing\r\n* Approximate equality checking for float values in dataframe \r\n* Other bug fixes\r\nThank you @gaugup, @bdavj, @DanieleMorotti for your contributions.\r\n","2023-10-26T11:36:48",{"id":160,"version":161,"summary_zh":162,"released_at":163},105287,"v0.10","* Support for python 3.11\r\n* Update to requirements and tests\r\n* Updated adult dataset download logic\r\n* Misc. bug fixes","2023-06-26T15:48:01",{"id":165,"version":166,"summary_zh":167,"released_at":168},105288,"v0.9","* [Major refactor] Unified API for deep learning and sklearn models\r\n* Support for generating CFs without training data (private data mode) for sklearn models\r\n* Bug fixes and implementing iteration limits for search on CFs\r\n\r\n## New Contributors\r\n* @lange-martin made their first contribution in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F304\r\n* @bgalvao made their first contribution in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F313\r\n* @daikikatsuragawa made their first contribution in https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fpull\u002F311\r\n\r\n**Full Changelog**: https:\u002F\u002Fgithub.com\u002Finterpretml\u002FDiCE\u002Fcompare\u002Fv0.8...v0.9","2022-10-19T11:30:46",{"id":170,"version":171,"summary_zh":172,"released_at":173},105289,"v0.8","* Better error checking for user input parameters\r\n* Improved error messages for feature importance functions\r\n* Bug fixes for dimension mismatch with categorical variables\r\n* Add capability to serialize and de-serialize dice-ml explainers\r\n* Add more configurable parameters to generate_counterfactuals function\r\n* Increased test coverage\r\n* Replaced boston housing with california housing dataset\r\n* Tests and support for Python 3.10, removed test support for 3.6\r\n\r\nContributors: @gaugup, @amit-sharma \r\n","2022-06-02T13:39:31",{"id":175,"version":176,"summary_zh":177,"released_at":178},105290,"v0.7.2","The release contains the following:-\r\n\r\n- Fix for logging\r\n- Fix indentation in schema files\r\n- Add documentation to save generated counterfactuals to disk","2021-09-27T06:59:35",{"id":180,"version":181,"summary_zh":182,"released_at":183},105291,"v0.7.1","* Better input checks and minor bug fixes","2021-08-24T06:53:40",{"id":185,"version":186,"summary_zh":187,"released_at":188},105292,"v0.7","* Bug fixes for feature importance calculation and data interfaces\r\n* Example notebooks: Use test data always to generate counterfactuals\r\n* Updates to the genetic algorithm and KD-tree algorithm\r\n* Better input validation and informative error messages for Dice explainers\r\n* Improved test coverage\r\n\r\nA big thank you to @gaugup and @soundarya98 for their contributions.\r\n","2021-08-17T13:07:08",{"id":190,"version":191,"summary_zh":192,"released_at":193},105293,"v0.6.1","* Added init so schema are packaged with distribution \r\n* All flake8 lint errors fixed. Flake8 validation is now enabled on all new commits.\r\n* Better automation for tests\r\n\r\nThank you @gaugup and @gregorybchris for your contributions!","2021-05-10T15:59:59",{"id":195,"version":196,"summary_zh":197,"released_at":198},105294,"v0.6","\r\n* Better exception handling for invalid user inputs (e.g., total_CFs=0)\r\n* Updated schema for serializing counterfactual explanations object\r\n* Better description for DiCE in getting started notebook\r\n* Add progress bar for counterfactual computation\r\n* Optimizations for genetic and random methods\r\n* Better test coverage\r\n\r\nThank you @gaugup and @soundarya88 for your contributions!","2021-04-28T11:50:40",{"id":200,"version":201,"summary_zh":202,"released_at":203},105295,"v0.5","* **[Major]** DiCE now supports sklearn models. Added three model-agnostic methods: randomized, genetic algorithm, and kd-tree\r\n* **[Major]** Support for regression and multi-class problems\r\n* **[Major]** Added local and global feature importance scores based on counterfactuals\r\n* **[Major]** Better support for customizing counterfactuals through `features_to_vary` and `permitted_range` parameters for both continuous and categorical features\r\n* **[Refactor]** ML Model and DiCE Explainer can use different feature transformations. Model's transformation can be provided as an input to the `dice_ml.Model` constructor. DiCE accepts inputs in the original data frame and does its transformations internally\r\n* Enhanced tests for the library\r\n* Deep learning libraries (tensorflow and pytorch) marked as optional dependencies\r\n* New notebooks showing applications of DiCE in `docs\u002Fsource\u002Fnotebooks\u002F`\r\n\r\nA big thanks to @raam93, @soundarya98 and @gaugup for this release!\r\n","2021-03-01T15:26:58",{"id":205,"version":206,"summary_zh":207,"released_at":208},105296,"v0.4","Here's the latest stable version. \r\n\r\n* DiCE now supports Pytorch, Tensorflow 1.x and 2.\r\n* Includes a Variational AutoEncoder-based method to generate counterfactual examples, based on https:\u002F\u002Farxiv.org\u002Fabs\u002F1912.03277. This method is much faster--try it out! \r\n* Support for private data, when only aggregate training data statistics are available to generate counterfactuals\r\n* Updated and faster post-hoc sparsity enhancer module for counterfactuals\r\n* Includes bug fixes for DiCE and tests for most DiCE functionalities. \r\n* More notebooks and detailed docs at http:\u002F\u002Finterpret.ml\u002FDiCE\u002F\r\n\r\nBig thanks to @raam93 for leading the updates, and to @divyat09 for adding the VAE method. ","2020-09-22T06:31:10",{"id":210,"version":211,"summary_zh":212,"released_at":213},105297,"v0.2","Supports counterfactual explanations for tensorflow and pytorch classifiers.","2020-03-17T09:41:52"]