[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-henrikbostrom--crepes":3,"tool-henrikbostrom--crepes":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":70,"readme_en":71,"readme_zh":72,"quickstart_zh":73,"use_case_zh":74,"hero_image_url":75,"owner_login":76,"owner_name":77,"owner_avatar_url":78,"owner_bio":79,"owner_company":80,"owner_location":79,"owner_email":79,"owner_twitter":79,"owner_website":81,"owner_url":82,"languages":83,"stars":88,"forks":89,"last_commit_at":90,"license":91,"difficulty_score":92,"env_os":93,"env_gpu":94,"env_ram":94,"env_deps":95,"category_tags":100,"github_topics":101,"view_count":23,"oss_zip_url":79,"oss_zip_packed_at":79,"status":16,"created_at":118,"updated_at":119,"faqs":120,"releases":150},2701,"henrikbostrom\u002Fcrepes","crepes","Python package for conformal prediction","crepes 是一个专为机器学习打造的 Python 开源库，致力于实现“共形预测”（Conformal Prediction）技术。在传统机器学习中，模型往往只给出一个预测结果却难以量化其可信度，而 crepes 能有效解决这一痛点。它可以将任意标准的分类器或回归器进行封装，把原本单一的预测值转化为具有数学覆盖率保证的预测区间、预测集合，或是校准良好的 P 值与累积分布函数。这意味着用户不仅能知道模型“预测了什么”，还能明确知晓该预测“有多可靠”。\n\n该工具特别适合数据科学家、AI 研究人员以及需要构建高可靠性决策系统的开发者使用。无论是处理医疗诊断、金融风控等对误差容忍度极低的场景，还是在进行严谨的学术研究，crepes 都能提供坚实的理论支撑。\n\n在技术亮点方面，crepes 不仅支持标准和 Mondrian 类型的共形分类与回归，还内置了归一化处理功能以应对不同难度的样本。此外，它提供了专门的模块用于计算非一致性分数，并包含独特的鞅（martingales）工具类，帮助用户验证数据交换性这一核心假设是否成立。通过简单的几行代码，用户即可将普通的随机森林等模型升级为具备不确定性量","crepes 是一个专为机器学习打造的 Python 开源库，致力于实现“共形预测”（Conformal Prediction）技术。在传统机器学习中，模型往往只给出一个预测结果却难以量化其可信度，而 crepes 能有效解决这一痛点。它可以将任意标准的分类器或回归器进行封装，把原本单一的预测值转化为具有数学覆盖率保证的预测区间、预测集合，或是校准良好的 P 值与累积分布函数。这意味着用户不仅能知道模型“预测了什么”，还能明确知晓该预测“有多可靠”。\n\n该工具特别适合数据科学家、AI 研究人员以及需要构建高可靠性决策系统的开发者使用。无论是处理医疗诊断、金融风控等对误差容忍度极低的场景，还是在进行严谨的学术研究，crepes 都能提供坚实的理论支撑。\n\n在技术亮点方面，crepes 不仅支持标准和 Mondrian 类型的共形分类与回归，还内置了归一化处理功能以应对不同难度的样本。此外，它提供了专门的模块用于计算非一致性分数，并包含独特的鞅（martingales）工具类，帮助用户验证数据交换性这一核心假设是否成立。通过简单的几行代码，用户即可将普通的随机森林等模型升级为具备不确定性量化能力的强大系统，让 AI 预测更加透明、可信。","\u003Cp align=\"center\">\u003Ca href=\"https:\u002F\u002Fcrepes.readthedocs.io\">\u003Cimg alt=\"crepes\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_0250e915f2ec.png\">\u003C\u002Fa>\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n\u003Ca href=\"https:\u002F\u002Fpypi.org\u002Fproject\u002Fcrepes\u002F\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpypi package-0.9.0-brightgreen\" alt=\"PyPI version\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fcrepes\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fconda--forge-0.9.0-orange\" alt=\"conda-forge version\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fpepy.tech\u002Fproject\u002Fcrepes\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_ee833376de16.png\" alt=\"Downloads\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_13d664e1afd7.png\" alt=\"docs status\" height=20 align=\"center\">\u003C\u002Fa> \n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Ftree\u002Fmain?tab=readme-ov-file#BSD-3-Clause-1-ov-file\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-BSD--3--clause-blue\" alt=\"License\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Freleases\u002Ftag\u002Fv0.9.0\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frelease-date\u002Fhenrikbostrom\u002Fcrepes\" alt=\"Release date\" height=20 align=\"center\">\u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cbr>\n\n`crepes` is a Python package for conformal prediction that implements conformal classifiers,\nregressors, and predictive systems on top of any standard classifier\nand regressor, turning the original predictions into\nwell-calibrated p-values and cumulative distribution functions, or\nprediction sets and intervals with coverage guarantees.\n\nThe `crepes` package implements standard and Mondrian conformal\nclassifiers as well as standard, normalized and Mondrian conformal\nregressors and predictive systems. While the package allows you to use\nyour own functions to compute difficulty estimates, non-conformity\nscores and Mondrian categories, there is also a separate module,\ncalled `crepes.extras`, which provides some standard options for\nthese. For testing the underlying assumption of exchangeability,\nyou may use the classes in the module `crepes.martingales`. \n\n## Installation\n\nFrom [PyPI](https:\u002F\u002Fpypi.org\u002Fproject\u002Fcrepes\u002F)\n\n```bash\npip install crepes\n```\n\nFrom [conda-forge](https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fcrepes)\n\n```bash\nconda install conda-forge::crepes\n```\n\n## Documentation\n\nFor the complete documentation, see [crepes.readthedocs.io](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002F).\n\n## Quickstart\n\nLet us illustrate how we may use `crepes` to generate and apply\nconformal classifiers with a dataset from\n[www.openml.org](https:\u002F\u002Fwww.openml.org), which we first split into a\ntraining and a test set using `train_test_split` from\n[sklearn](https:\u002F\u002Fscikit-learn.org), and then further split the\ntraining set into a proper training set and a calibration set:\n\n```python\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split\n\ndataset = fetch_openml(name=\"qsar-biodeg\", parser=\"auto\")\n\nX = dataset.data.values.astype(float)\ny = dataset.target.values\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)\n\nX_prop_train, X_cal, y_prop_train, y_cal = train_test_split(X_train, y_train,\n                                                            test_size=0.25)\n```\n\nWe now \"wrap\" a random forest classifier, fit it to the proper\ntraining set, and fit a standard conformal classifier through the\n`calibrate` method:\n\n```python\nfrom crepes import WrapClassifier\nfrom sklearn.ensemble import RandomForestClassifier\n\nrf = WrapClassifier(RandomForestClassifier(n_jobs=-1))\n\nrf.fit(X_prop_train, y_prop_train)\n\nrf.calibrate(X_cal, y_cal)\n```\n\nWe may now produce p-values for the test set (an array with as many\ncolumns as there are classes):\n\n```python\nrf.predict_p(X_test)\n```\n\n```numpy\narray([[0.00427104, 0.74842304],\n       [0.07874355, 0.2950549 ],\n       [0.50529983, 0.01557963],\n       ...,\n       [0.8413356 , 0.00201167],\n       [0.84402215, 0.00654927],\n       [0.29601955, 0.07766093]])\n```\n\nWe can also get prediction sets, represented by binary vectors\nindicating presence (1) or absence (0) of the class labels that\ncorrespond to the columns, here at the 90% confidence level:\n\n```python\nrf.predict_set(X_test, confidence=0.9)\n```\n\n```numpy\narray([[0, 1],\n       [0, 1],\n       [1, 0],\n       ...,\n       [1, 0],\n       [1, 0],\n       [1, 0]])\n```\n\nSince we have access to the true class labels, we can evaluate the\nconformal classifier (here using all available metrics which is the\ndefault), at the 99% confidence level:\n\n```python\nrf.evaluate(X_test, y_test, confidence=0.99)\n```\n\n```python\n{'error': 0.007575757575757569,\n 'avg_c': 1.6325757575757576,\n 'one_c': 0.36742424242424243,\n 'empty': 0.0,\n 'ks_test': 0.0033578466103315894,\n 'time_fit': 1.9073486328125e-06,\n 'time_evaluate': 0.04798746109008789}\n```\n\nTo control the error level across different groups of objects of\ninterest, we may use so-called Mondrian conformal classifiers. A\nMondrian conformal classifier is formed by providing a function or a\n`MondrianCategorizer` (defined in `crepes.extras`) as an additional\nargument, named `mc`, for the `calibrate` method.\n\nFor illustration, we will use the predicted labels of the underlying\nmodel to form the categories. Note that the prediction sets are generated\nfor the test objects using the same categorization (under the hood).\n\n```python\nrf_mond = WrapClassifier(rf.learner)\n\nrf_mond.calibrate(X_cal, y_cal, mc=rf_mond.predict)\n\nrf_mond.predict_set(X_test)\n```\n\n```numpy\narray([[0, 1],\n       [1, 1],\n       [1, 0],\n       ...,\n       [1, 0],\n       [1, 0],\n       [1, 1]])\n```\n\nThe class-conditional conformal classifier is a special type of Mondrian\nconformal classifier, for which the categories are formed by the true labels;\nwe can generate one by setting `class_cond=True` in the call to `calibrate`\n\n```python\nrf_classcond = WrapClassifier(rf.learner)\n\nrf_classcond.calibrate(X_cal, y_cal, class_cond=True)\n\nrf_classcond.evaluate(X_test, y_test, confidence=0.99)\n```\n\n```python\n{'error': 0.0018939393939394478,\n 'avg_c': 1.740530303030303,\n 'one_c': 0.25946969696969696,\n 'empty': 0.0,\n 'ks_test': 0.11458837583733483,\n 'time_fit': 7.152557373046875e-07,\n 'time_evaluate': 0.06147575378417969}\n ```\n\nWhen employing an inductive conformal predictor, the predicted\np-values (and consequently the errors made) for a test set are not\nindependent. Semi-online conformal predictors can however make them\nindependent by updating the calibration set immediately after each\nprediction (assuming that the true label is then available). We can\nturn the conformal classifiers into semi-online conformal classifiers\nby enabling online calibration, i.e., setting `online=True` when calling\nthe above methods, while also providing the true labels, e.g.,\n\n```python\nrf_classcond.predict_p(X_test, y_test, online=True)\n```\n\n```numpy\narray([[8.13837566e-05, 8.86436603e-01],\n       [6.60518590e-02, 4.02350293e-01],\n       [4.28646783e-01, 4.29930890e-02],\n       ...,\n       [7.05118942e-01, 9.45056960e-03],\n       [7.27003479e-01, 1.27347189e-02],\n       [1.76403756e-01, 1.21434924e-01]])\n```\n\nSimilarly, we can evaluate the conformal classifier while using online\ncalibration:\n\n```python\nrf_classcond.evaluate(X_test, y_test, confidence=0.99, online=True)\n```\n\n```python\n{'error': 0.007575757575757569,\n 'avg_c': 1.6117424242424243,\n 'one_c': 0.38825757575757575,\n 'empty': 0.0,\n 'ks_test': 0.14097384777782784,\n 'time_fit': 1.9073486328125e-06,\n 'time_evaluate': 0.05298352241516113}\n```\n\nLet us also illustrate how `crepes` can be used to generate conformal\nregressors and predictive systems. Again, we import a dataset from\n[www.openml.org](https:\u002F\u002Fwww.openml.org), which we split into a\ntraining and a test set and then further split the training set into a\nproper training set and a calibration set:\n\n```python\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split\n\ndataset = fetch_openml(name=\"house_sales\", version=3, parser=\"auto\")\n\nX = dataset.data.values.astype(float)\ny = dataset.target.values.astype(float)\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)\nX_prop_train, X_cal, y_prop_train, y_cal = train_test_split(X_train, y_train,\n                                                            test_size=0.25)\n```\n\nLet us now \"wrap\" a `RandomForestRegressor` from\n[sklearn](https:\u002F\u002Fscikit-learn.org) using the class `WrapRegressor`\nfrom `crepes` and fit it (in the usual way) to the proper training\nset:\n\n```python\nfrom sklearn.ensemble import RandomForestRegressor\nfrom crepes import WrapRegressor\n\nrf = WrapRegressor(RandomForestRegressor())\nrf.fit(X_prop_train, y_prop_train)\n```\n\nWe may now fit a conformal regressor using the calibration set through\nthe `calibrate` method:\n\n```python\nrf.calibrate(X_cal, y_cal)\n```\n\nThe conformal regressor can now produce prediction intervals for the\ntest set, here using a confidence level of 99%:\n\n```python\nrf.predict_int(X_test, confidence=0.99)\n```\n\n```numpy\narray([[1938866.06, 3146372.54],\n       [ 225335.1 , 1432841.58],\n       [-403305.49,  804200.99],\n       ...,\n       [ 443742.33, 1651248.81],\n       [-343684.48,  863822.  ],\n       [-153629.93, 1053876.55]])\n```\n\nThe output is a [NumPy](https:\u002F\u002Fnumpy.org) array with a row for each\ntest instance, and where the two columns specify the lower and upper\nbound of each prediction interval.\n\nWe may request that the intervals are cut to exclude impossible\nvalues, in this case below 0, and if we also rely on the default\nconfidence level (0.95), the output intervals will be a bit tighter:\n\n```python\nrf.predict_int(X_test, y_min=0)\n```\n\n```numpy\narray([[2302049.84, 2783188.76],\n       [ 588518.88, 1069657.8 ],\n       [      0.  ,  441017.21],\n       ...,\n       [ 806926.11, 1288065.03],\n       [  19499.3 ,  500638.22],\n       [ 209553.85,  690692.77]])\n```\n\nThe above intervals are not normalized, i.e., they are all of the same\nsize (at least before they are cut). We could make them more\ninformative through normalization using difficulty estimates; objects\nconsidered more difficult will be assigned wider intervals.\n\nWe will use a `DifficultyEstimator` from the `crepes.extras` module\nfor this purpose. Here we estimate the difficulty by the standard\ndeviation of the target of the k (default `k=25`) nearest neighbors in\nthe proper training set to each object in the calibration set. A small\nvalue (beta) is added to the estimates, which may be given through an\nargument to the function; below we just use the default, i.e.,\n`beta=0.01`.\n\nWe first fit the difficulty estimator and then calibrate the conformal\nregressor, using the calibration objects and labels together the\ndifficulty estimator:\n\n```python\nfrom crepes.extras import DifficultyEstimator\n\nde = DifficultyEstimator()\nde.fit(X_prop_train, y=y_prop_train)\n\nrf.calibrate(X_cal, y_cal, de=de)\n```\n\nTo obtain prediction intervals, we just have to provide test objects\nto the `predict_int` method, as the difficulty estimates will be\ncomputed by the incorporated difficulty estimator:\n\n```python\nrf.predict_int(X_test, y_min=0)\n```\n\n```numpy\narray([[1769594.36212355, 3315644.23787645],\n       [ 693827.99796647,  964348.68203353],\n       [ 124886.97469338,  276008.52530662],\n       ...,\n       [ 661373.45043166, 1433617.68956833],\n       [ 178769.2939384 ,  341368.2260616 ],\n       [ 222837.12801117,  677409.49198883]])\n```\n\nDepending on the employed difficulty estimator, the normalized\nintervals may sometimes be unreasonably large, in the sense that they\nmay be several times larger than any previously observed\nerror. Moreover, if the difficulty estimator is uninformative, e.g.,\ncompletely random, the varying interval sizes may give a false\nimpression of that we can expect lower prediction errors for instances\nwith tighter intervals. Ideally, a difficulty estimator providing\nlittle or no information on the expected error should instead lead to\nmore uniformly distributed interval sizes.\n\nA Mondrian conformal regressor can be used to address these problems,\nby dividing the object space into non-overlapping so-called Mondrian\ncategories, and forming a (standard) conformal regressor for each\ncategory. We may form a Mondrian conformal regressor by providing a\nfunction or a `MondrianCategorizer` (defined in `crepes.extras`) as an\nadditional argument, named `mc`, for the `calibrate` method.\n\nHere we employ a `MondrianCategorizer`; it may be fitted in several\ndifferent ways, and below we show how to form categories by binning of\nthe difficulty estimates into 20 bins, using the difficulty estimator\nfitted above.\n\n```python\nfrom crepes.extras import MondrianCategorizer\n\nmc_diff = MondrianCategorizer()\nmc_diff.fit(X_cal, de=de, no_bins=20)\n\nrf.calibrate(X_cal, y_cal, mc=mc_diff)\n```\n\nWhen making predictions, the test objects will be assigned to Mondrian categories\naccording to the incorporated `MondrianCategorizer` (or labeling function):\n\n```python\nrf.predict_int(X_test, y_min=0)\n```\n\n```numpy\narray([[1152528.9 , 3932709.7 ],\n       [ 692366.75,  965809.93],\n       [ 124254.81,  276640.69],\n       ...,\n       [ 622939.57, 1472051.57],\n       [ 155346.82,  364790.7 ],\n       [ 239474.31,  660772.31]])\n```\n\nSimilarly to semi-online conformal classifiers, we may enable online calibration\nalso for conformal regressors; this is again done by setting `online=True` when\ncalling any of the applicable methods, while also providing the true labels, e.g.,\n\n```python\nrf.predict_p(X_test, y_test, online=True)\n```\n\n```numpy\narray([0.09369225, 0.52548032, 0.49992477, ..., 0.72979714, 0.87495964,\n       0.58352253])\n```\n\nWe can easily switch from conformal regressors to conformal\npredictive systems. The latter produce cumulative distribution\nfunctions (conformal predictive distributions). From these we can\ngenerate prediction intervals, but we can also obtain percentiles,\ncalibrated point predictions, as well as p-values for given target\nvalues. Let us see how we can go ahead to do that.\n\nWell, there is only one thing above that changes: just provide\n`cps=True` to the `calibrate` method.\n\nWe can, for example, form normalized Mondrian conformal predictive\nsystems, by providing both a Mondrian categorizer and difficulty estimator\nto the `calibrate` method. Here we will consider Mondrian categories formed\nfrom binning the point predictions:\n\n```python\nmc_pred = MondrianCategorizer()\nmc_pred.fit(X_cal, f=rf.predict, no_bins=5)\n\nrf.calibrate(X_cal, y_cal, de=de, mc=mc_pred, cps=True)\n```\n\nWe can now make predictions with the conformal predictive system,\nthrough several different methods, e.g., `predict_percentiles`:\n\n```python\nrf.predict_percentiles(X_test, higher_percentiles=[90, 95, 99])\n```\n\n```numpy\narray([[3120432.14791764, 3403976.16608241, 3952384.13595105],\n       [ 930191.36994287,  979804.59585495, 1075762.49571536],\n       [ 236278.82580469,  253387.66592079,  329933.49293406],\n       ...,\n       [1336110.21956702, 1477739.04927264, 1751666.10820498],\n       [ 298621.13482031,  317029.35735016,  399388.68783836],\n       [ 564574.75363948,  615226.06727944,  762212.9912238 ]])\n```\n\nSimilarly to semi-online conformal classifiers and regressors, we can enable\nonline calibration also for conformal predictive systems; here we generate\nprediction intervals at the default (95%) confidence level:\n\n```python\nrf.predict_int(X_test, y_test, y_min=0, online=True)\n```\n\n```numpy\narray([[1719676.80439219, 3707173.76806116],\n       [ 684289.27240227, 1032856.71531186],\n       [ 127189.61835749,  274385.59426486],\n       ...,\n       [ 630347.70469164, 1594876.58130005],\n       [ 167399.51044545,  337513.60197203],\n       [ 232815.51352497,  641580.14787679]])\n```\n\nWe may also obtain the full conformal predictive distribution for each test\ninstance, as defined by the threshold values:\n\n```python\nrf.predict_cpds(X_test)\n```\n\nFor a Mondrian conformal predictive system (or any semi-online conformal\npredictive system), the output is a vector containing one CPD per test instance,\nwhile for a standard or normalized conformal predictive system (for which online\ncalibration is not enabled), the output is a 2-dimensional array.\n\nThe resulting vector of vectors is not displayed here, but we instead provide a plot\nfor the CPD of a random test instance:\n\n![cpd](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_863320d83bb7.png)\n\nWe may also test the exchangeability assumption using conformal test martingales. Assume that we\nhave obtained p-values using a semi-online conformal predictor, e.g.,\n\n```python\np_values = rf.predict_p(X_test, y_test, online=True)\n```\n\nWe can now test if the p-values are distributed independently and uniformly over [0, 1] using any of the\navailable conformal test martingale algorithms in ``crepes.martingales``. If the exchangeability assumption\nholds then the probability of observing a martingale value exceeding c is less than or equal to 1\u002Fc.\nThis means that probability of incorrectly rejecting the assumption is bounded by 1\u002Fc. We here show\nhow to obtain martingale values for the above p-values using Simple Jumper:\n\n```python\nfrom crepes.martingales import SimpleJumper\n\nmartingale_values = SimpleJumper().apply(p_values)\n```\n\nWe may also ask for the lowest index for which the martingale value exceeds a specified threshold:\n\n```python\nSimpleJumper().apply(np.sort(p_values), c=100)\n```\n\nSince the p-values are sorted in the above example, the conformal test martingale will detect a violation of the exchangeability assumption early on and return a low index. If instead the original (unsorted) p-values are provided, it is very likely that the conformal test martingale will not detect any data drift and will just return the length of the p-value vector.\n\n## Examples\n\nFor additional examples of how to use the package and module, see [the documentation](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002F), [this Jupyter notebook using WrapClassifier and WrapRegressor](https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002Fcrepes_nb_wrap.ipynb), [this Jupyter notebook using ConformalClassifier, ConformalRegressor, and ConformalPredictiveSystem](https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002Fcrepes_nb.ipynb) and [this Jupyter notebook on the use of conformal test martingales](https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002Fmartingales_nb.ipynb).\n\nYou may also take a look at the [slides from my tutorial at COPA 2024](\u003Chttps:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002FCOPA Tutorial 2024.pdf>) and the accompanying [Jupyter notebook](\u003Chttps:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002FCOPA Tutorial 2024.ipynb>).\n\n## Citing crepes\n\nYou are welcome to cite the following paper:\n\nBoström, H. 2024. Conformal Prediction in Python with crepes. Proceedings of the 13th Symposium on Conformal and Probabilistic Prediction with Applications, PMLR 230:236-249 [Link](https:\u002F\u002Fraw.githubusercontent.com\u002Fmlresearch\u002Fv230\u002Fmain\u002Fassets\u002Fbostrom24a\u002Fbostrom24a.pdf)\n\nBibtex entry:\n\n```bibtex\n@inproceedings{bostrom2024,\n  title={Conformal Prediction in Python with crepes},\n  author={Bostr{\\\"o}m, Henrik},\n  booktitle={Proc. of the 13th Symposium on Conformal and Probabilistic Prediction with Applications},\n  pages={236--249},\n  year={2024},\n  organization={PMLR}\n}\n```\n\nAn early version of the package was described in:\n\nBoström, H., 2022. crepes: a Python Package for Generating Conformal Regressors and Predictive Systems. Proceedings of the 11th Symposium on Conformal and Probabilistic Prediction with Applications, PMLR 179:24-41 [Link](https:\u002F\u002Fproceedings.mlr.press\u002Fv179\u002Fbostrom22a\u002Fbostrom22a.pdf)\n\nBibtex entry:\n\n```bibtex\n@inproceedings{bostrom2022,\n  title={crepes: a Python Package for Generating Conformal Regressors and Predictive Systems},\n  author={Bostr{\\\"o}m, Henrik},\n  booktitle={Proc. of the 11th Symposium on Conformal and Probabilistic Prediction with Applications},\n  pages={24--41},\n  year={2022},\n  organization={PMLR}\n}\n```\n\n## References\n\n\u003Ca id=\"1\">[1]\u003C\u002Fa> Vovk, V., Gammerman, A. and Shafer, G., 2022. Algorithmic learning in a random world. 2nd edition. Springer [Link](https:\u002F\u002Flink.springer.com\u002Fbook\u002F10.1007\u002F978-3-031-06649-8)\n\n\u003Ca id=\"2\">[2]\u003C\u002Fa> Papadopoulos, H., Proedrou, K., Vovk, V. and Gammerman, A., 2002. Inductive confidence machines for regression. European Conference on Machine Learning, pp. 345-356. [Link](https:\u002F\u002Flink.springer.com\u002Fchapter\u002F10.1007\u002F3-540-36755-1_29)\n\n\u003Ca id=\"3\">[3]\u003C\u002Fa> Johansson, U., Boström, H., Löfström, T. and Linusson, H., 2014. Regression conformal prediction with random forests. Machine learning, 97(1-2), pp. 155-176. [Link](https:\u002F\u002Flink.springer.com\u002Farticle\u002F10.1007\u002Fs10994-014-5453-0)\n\n\u003Ca id=\"4\">[4]\u003C\u002Fa> Boström, H., Linusson, H., Löfström, T. and Johansson, U., 2017. Accelerating difficulty estimation for conformal regression forests. Annals of Mathematics and Artificial Intelligence, 81(1-2), pp.125-144. [Link](https:\u002F\u002Flink.springer.com\u002Farticle\u002F10.1007\u002Fs10472-017-9539-9)\n\n\u003Ca id=\"5\">[5]\u003C\u002Fa> Boström, H. and Johansson, U., 2020. Mondrian conformal regressors. In Conformal and Probabilistic Prediction and Applications. PMLR, 128, pp. 114-133. [Link](https:\u002F\u002Fproceedings.mlr.press\u002Fv128\u002Fbostrom20a.html)\n\n\u003Ca id=\"6\">[6]\u003C\u002Fa> Vovk, V., Petej, I., Nouretdinov, I., Manokhin, V. and Gammerman, A., 2020. Computationally efficient versions of conformal predictive distributions. Neurocomputing, 397, pp.292-308. [Link](https:\u002F\u002Fwww.aminer.org\u002Fpub\u002F5e09aac9df1a9c0c416c9b70\u002Fcomputationally-efficient-versions-of-conformal-predictive-distributions)\n\n\u003Ca id=\"7\">[7]\u003C\u002Fa> Boström, H., Johansson, U. and Löfström, T., 2021. Mondrian conformal predictive distributions. In Conformal and Probabilistic Prediction and Applications. PMLR, 152, pp. 24-38. [Link](https:\u002F\u002Fproceedings.mlr.press\u002Fv152\u002Fbostrom21a.html)\n\n\u003Ca id=\"8\">[8]\u003C\u002Fa> Vovk, V., 2022. Universal predictive systems. Pattern Recognition. 126: pp. 108536 [Link](https:\u002F\u002Fdl.acm.org\u002Fdoi\u002Fabs\u002F10.1016\u002Fj.patcog.2022.108536)\n\n\n- - -\n\nAuthor: Henrik Boström (bostromh@kth.se)\nCopyright 2025 Henrik Boström\nLicense: BSD 3 clause\n","\u003Cp align=\"center\">\u003Ca href=\"https:\u002F\u002Fcrepes.readthedocs.io\">\u003Cimg alt=\"crepes\" src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_0250e915f2ec.png\">\u003C\u002Fa>\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n\u003Ca href=\"https:\u002F\u002Fpypi.org\u002Fproject\u002Fcrepes\u002F\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpypi package-0.9.0-brightgreen\" alt=\"PyPI版本\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fcrepes\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fconda--forge-0.9.0-orange\" alt=\"conda-forge版本\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fpepy.tech\u002Fproject\u002Fcrepes\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_ee833376de16.png\" alt=\"下载量\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\">\u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_13d664e1afd7.png\" alt=\"文档状态\" height=20 align=\"center\">\u003C\u002Fa> \n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Ftree\u002Fmain?tab=readme-ov-file#BSD-3-Clause-1-ov-file\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-BSD--3--clause-blue\" alt=\"许可证\" height=20 align=\"center\">\u003C\u002Fa>\n\u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Freleases\u002Ftag\u002Fv0.9.0\">\u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fgithub\u002Frelease-date\u002Fhenrikbostrom\u002Fcrepes\" alt=\"发布日期\" height=20 align=\"center\">\u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cbr>\n\n`crepes` 是一个用于共形预测的 Python 包，它可以在任何标准分类器和回归器之上实现共形分类器、回归器以及预测系统，从而将原始预测转化为校准良好的 p 值和累积分布函数，或具有覆盖率保证的预测集和预测区间。\n\n`crepes` 包实现了标准和蒙德里安共形分类器，以及标准、归一化和蒙德里安共形回归器和预测系统。虽然该包允许用户使用自己的函数来计算难度估计、非一致性分数和蒙德里安类别，但还有一个名为 `crepes.extras` 的独立模块，提供了这些方面的若干标准选项。为了检验交换性的基本假设，可以使用 `crepes.martingales` 模块中的类。\n\n## 安装\n\n从 [PyPI](https:\u002F\u002Fpypi.org\u002Fproject\u002Fcrepes\u002F)：\n\n```bash\npip install crepes\n```\n\n从 [conda-forge](https:\u002F\u002Fanaconda.org\u002Fconda-forge\u002Fcrepes)：\n\n```bash\nconda install conda-forge::crepes\n```\n\n## 文档\n\n完整的文档请参阅 [crepes.readthedocs.io](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002F)。\n\n## 快速入门\n\n让我们以来自 [www.openml.org](https:\u002F\u002Fwww.openml.org) 的数据集为例，说明如何使用 `crepes` 生成并应用共形分类器。我们首先使用 [sklearn](https:\u002F\u002Fscikit-learn.org) 中的 `train_test_split` 将数据集划分为训练集和测试集，然后进一步将训练集划分为正式训练集和校准集：\n\n```python\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split\n\ndataset = fetch_openml(name=\"qsar-biodeg\", parser=\"auto\")\n\nX = dataset.data.values.astype(float)\ny = dataset.target.values\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)\n\nX_prop_train, X_cal, y_prop_train, y_cal = train_test_split(X_train, y_train,\n                                                            test_size=0.25)\n```\n\n现在我们将随机森林分类器“包装”起来，将其拟合到正式训练集，并通过 `calibrate` 方法拟合一个标准共形分类器：\n\n```python\nfrom crepes import WrapClassifier\nfrom sklearn.ensemble import RandomForestClassifier\n\nrf = WrapClassifier(RandomForestClassifier(n_jobs=-1))\n\nrf.fit(X_prop_train, y_prop_train)\n\nrf.calibrate(X_cal, y_cal)\n```\n\n接下来，我们可以为测试集生成 p 值（一个列数等于类别数的数组）：\n\n```python\nrf.predict_p(X_test)\n```\n\n```numpy\narray([[0.00427104, 0.74842304],\n       [0.07874355, 0.2950549 ],\n       [0.50529983, 0.01557963],\n       ...,\n       [0.8413356 , 0.00201167],\n       [0.84402215, 0.00654927],\n       [0.29601955, 0.07766093]])\n```\n\n我们还可以得到预测集，用二进制向量表示，其中 1 表示存在、0 表示不存在与列对应的类标签，在这里置信度为 90%：\n\n```python\nrf.predict_set(X_test, confidence=0.9)\n```\n\n```numpy\narray([[0, 1],\n       [0, 1],\n       [1, 0],\n       ...,\n       [1, 0],\n       [1, 0],\n       [1, 0]])\n```\n\n由于我们掌握了真实的类标签，因此可以在 99% 的置信度下评估共形分类器（此处使用所有可用指标，这是默认设置）：\n\n```python\nrf.evaluate(X_test, y_test, confidence=0.99)\n```\n\n```python\n{'error': 0.007575757575757569,\n 'avg_c': 1.6325757575757576,\n 'one_c': 0.36742424242424243,\n 'empty': 0.0,\n 'ks_test': 0.0033578466103315894,\n 'time_fit': 1.9073486328125e-06,\n 'time_evaluate': 0.04798746109008789}\n```\n\n为了控制不同目标群体中的错误率，可以使用所谓的蒙德里安共形分类器。蒙德里安共形分类器是通过在 `calibrate` 方法中提供一个函数或 `MondrianCategorizer`（定义在 `crepes.extras` 中），作为名为 `mc` 的额外参数来构建的。\n\n为了说明，我们将使用底层模型的预测标签来形成类别。请注意，测试对象的预测集是基于相同的分类方式生成的（在后台进行）。\n\n```python\nrf_mond = WrapClassifier(rf.learner)\n\nrf_mond.calibrate(X_cal, y_cal, mc=rf_mond.predict)\n\nrf_mond.predict_set(X_test)\n```\n\n```numpy\narray([[0, 1],\n       [1, 1],\n       [1, 0],\n       ...,\n       [1, 0],\n       [1, 0],\n       [1, 1]])\n```\n\n条件类共形分类器是蒙德里安共形分类器的一种特殊类型，其类别由真实标签构成；我们可以通过在调用 `calibrate` 时设置 `class_cond=True` 来生成一个。\n\n```python\nrf_classcond = WrapClassifier(rf.learner)\n\nrf_classcond.calibrate(X_cal, y_cal, class_cond=True)\n\nrf_classcond.evaluate(X_test, y_test, confidence=0.99)\n```\n\n```python\n{'error': 0.0018939393939394478,\n 'avg_c': 1.740530303030303,\n 'one_c': 0.25946969696969696,\n 'empty': 0.0,\n 'ks_test': 0.11458837583733483,\n 'time_fit': 7.152557373046875e-07,\n 'time_evaluate': 0.06147575378417969}\n```\n\n当使用归纳式共形预测器时，测试集上的预测 p 值（以及由此产生的误差）并不相互独立。然而，半在线共形预测器可以通过在每次预测后立即更新校准集来使它们相互独立（假设此时已知真实标签）。我们可以通过启用在线校准，即在调用上述方法时设置 `online=True`，同时提供真实标签，将共形分类器转变为半在线共形分类器，例如：\n\n```python\nrf_classcond.predict_p(X_test, y_test, online=True)\n```\n\n```numpy\narray([[8.13837566e-05, 8.86436603e-01],\n       [6.60518590e-02, 4.02350293e-01],\n       [4.28646783e-01, 4.29930890e-02],\n       ...,\n       [7.05118942e-01, 9.45056960e-03],\n       [7.27003479e-01, 1.27347189e-02],\n       [1.76403756e-01, 1.21434924e-01]])\n```\n\n同样地，我们也可以在使用在线校准的情况下评估共形分类器：\n\n```python\nrf_classcond.evaluate(X_test, y_test, confidence=0.99, online=True)\n```\n\n```python\n{'error': 0.007575757575757569,\n 'avg_c': 1.6117424242424243,\n 'one_c': 0.38825757575757575,\n 'empty': 0.0,\n 'ks_test': 0.14097384777782784,\n 'time_fit': 1.9073486328125e-06,\n 'time_evaluate': 0.05298352241516113}\n```\n\n我们还可以说明如何使用 `crepes` 来生成共形回归模型和预测系统。再次从 [www.openml.org](https:\u002F\u002Fwww.openml.org) 导入数据集，将其分为训练集和测试集，然后将训练集进一步划分为正式训练集和校准集：\n\n```python\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split\n\ndataset = fetch_openml(name=\"house_sales\", version=3, parser=\"auto\")\n\nX = dataset.data.values.astype(float)\ny = dataset.target.values.astype(float)\n\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)\nX_prop_train, X_cal, y_prop_train, y_cal = train_test_split(X_train, y_train,\n                                                            test_size=0.25)\n```\n\n现在，我们使用 `crepes` 中的 `WrapRegressor` 类“包装”来自 [sklearn](https:\u002F\u002Fscikit-learn.org) 的 `RandomForestRegressor`，并按照常规方式将其拟合到正式训练集：\n\n```python\nfrom sklearn.ensemble import RandomForestRegressor\nfrom crepes import WrapRegressor\n\nrf = WrapRegressor(RandomForestRegressor())\nrf.fit(X_prop_train, y_prop_train)\n```\n\n接下来，我们可以通过 `calibrate` 方法利用校准集来拟合共形回归模型：\n\n```python\nrf.calibrate(X_cal, y_cal)\n```\n\n此时，共形回归模型可以为测试集生成预测区间，这里我们使用 99% 的置信水平：\n\n```python\nrf.predict_int(X_test, confidence=0.99)\n```\n\n```numpy\narray([[1938866.06, 3146372.54],\n       [ 225335.1 , 1432841.58],\n       [-403305.49,  804200.99],\n       ...,\n       [ 443742.33, 1651248.81],\n       [-343684.48,  863822.  ],\n       [-153629.93, 1053876.55]])\n```\n\n输出是一个 [NumPy](https:\u002F\u002Fnumpy.org) 数组，每一行对应一个测试样本，两列分别表示每个预测区间的下界和上界。\n\n我们可以要求对区间进行裁剪，以排除不可能的值，在本例中即低于 0 的值；如果同时采用默认的置信水平（0.95），则输出的区间会更加紧凑：\n\n```python\nrf.predict_int(X_test, y_min=0)\n```\n\n```numpy\narray([[2302049.84, 2783188.76],\n       [ 588518.88, 1069657.8 ],\n       [      0.  ,  441017.21],\n       ...,\n       [ 806926.11, 1288065.03],\n       [  19499.3 ,  500638.22],\n       [ 209553.85,  690692.77]])\n```\n\n上述区间并未归一化，也就是说它们的大小都相同（至少在裁剪之前是如此）。我们可以通过使用难度估计来进行归一化，从而使区间更具信息量：被认为更难的对象将被分配到更宽的区间。\n\n为此，我们将使用 `crepes.extras` 模块中的 `DifficultyEstimator`。在这里，我们通过计算校准集中每个对象在其正式训练集中 k 个（默认 k=25）最近邻的标签标准差来估计难度。此外，还会向估计值添加一个小的常数 β，该参数可通过函数参数指定；下面我们直接使用默认值，即 β=0.01。\n\n首先拟合难度估计器，然后结合校准对象及其标签以及难度估计器来校准共形回归模型：\n\n```python\nfrom crepes.extras import DifficultyEstimator\n\nde = DifficultyEstimator()\nde.fit(X_prop_train, y=y_prop_train)\n\nrf.calibrate(X_cal, y_cal, de=de)\n```\n\n要获得预测区间，只需将测试对象传递给 `predict_int` 方法即可，因为难度估计将由内置的难度估计器自动计算：\n\n```python\nrf.predict_int(X_test, y_min=0)\n```\n\n```numpy\narray([[1769594.36212355, 3315644.23787645],\n       [ 693827.99796647,  964348.68203353],\n       [ 124886.97469338,  276008.52530662],\n       ...,\n       [ 661373.45043166, 1433617.68956833],\n       [ 178769.2939384 ,  341368.2260616 ],\n       [ 222837.12801117,  677409.49198883]])\n```\n\n根据所使用的难度估计器，归一化的区间有时可能会大得不合理，甚至可能是先前观察到的最大误差的数倍。此外，如果难度估计器毫无信息量，例如完全随机，则不同大小的区间可能会给人造成一种错觉，即认为具有较窄区间的情况其预测误差会更低。理想情况下，对于那些几乎无法提供有关预期误差信息的难度估计器，应该导致区间大小更加均匀分布。\n\nMondrian 共形回归模型可以用来解决这些问题，它通过将对象空间划分为互不重叠的所谓 Mondrian 类别，并为每个类别构建一个（标准）共形回归模型。我们可以通过在 `calibrate` 方法中提供一个函数或 `MondrianCategorizer`（定义在 `crepes.extras` 中），作为名为 `mc` 的额外参数，来构建 Mondrian 共形回归模型。\n\n这里我们使用 `MondrianCategorizer`；它可以以多种方式拟合，下面展示的是如何利用上面拟合的难度估计器，将难度估计值分成 20 个桶来形成类别。\n\n```python\nfrom crepes.extras import MondrianCategorizer\n\nmc_diff = MondrianCategorizer()\nmc_diff.fit(X_cal, de=de, no_bins=20)\n\nrf.calibrate(X_cal, y_cal, mc=mc_diff)\n```\n\n在进行预测时，测试对象将根据内置的 `MondrianCategorizer`（或标注函数）被分配到相应的 Mondrian 类别：\n\n```python\nrf.predict_int(X_test, y_min=0)\n```\n\n```numpy\narray([[1152528.9 , 3932709.7 ],\n       [ 692366.75,  965809.93],\n       [ 124254.81,  276640.69],\n       ...,\n       [ 622939.57, 1472051.57],\n       [ 155346.82,  364790.7 ],\n       [ 239474.31,  660772.31]])\n```\n\n与半在线共形分类器类似，我们也可以为共形回归模型启用在线校准；这同样是通过在调用相关方法时设置 `online=True` 来实现的，同时还需要提供真实的标签，例如：\n\n```python\nrf.predict_p(X_test, y_test, online=True)\n```\n\n```numpy\narray([0.09369225, 0.52548032, 0.49992477, ..., 0.72979714, 0.87495964,\n       0.58352253])\n```\n\n我们可以很容易地从共形回归器切换到共形预测系统。后者会生成累积分布函数（共形预测分布）。基于这些分布，我们不仅可以生成预测区间，还可以得到分位数、校准后的点预测以及针对给定目标值的 p 值。接下来我们就来看看如何实现这一点。\n\n其实只需要在 `calibrate` 方法中添加一个参数：将 `cps=True` 传入即可。\n\n例如，我们可以通过向 `calibrate` 方法同时提供 Mondrian 分类器和难度估计器，来构建归一化的 Mondrian 共形预测系统。这里我们将考虑根据点预测结果进行分箱后形成的 Mondrian 类别：\n\n```python\nmc_pred = MondrianCategorizer()\nmc_pred.fit(X_cal, f=rf.predict, no_bins=5)\n\nrf.calibrate(X_cal, y_cal, de=de, mc=mc_pred, cps=True)\n```\n\n现在我们可以使用共形预测系统进行预测，方法有多种，比如 `predict_percentiles`：\n\n```python\nrf.predict_percentiles(X_test, higher_percentiles=[90, 95, 99])\n```\n\n```numpy\narray([[3120432.14791764, 3403976.16608241, 3952384.13595105],\n       [ 930191.36994287,  979804.59585495, 1075762.49571536],\n       [ 236278.82580469,  253387.66592079,  329933.49293406],\n       ...,\n       [1336110.21956702, 1477739.04927264, 1751666.10820498],\n       [ 298621.13482031,  317029.35735016,  399388.68783836],\n       [ 564574.75363948,  615226.06727944,  762212.9912238 ]])\n```\n\n与半在线共形分类器和回归器类似，我们也可以为共形预测系统启用在线校准；这里我们以默认的 95% 置信水平生成预测区间：\n\n```python\nrf.predict_int(X_test, y_test, y_min=0, online=True)\n```\n\n```numpy\narray([[1719676.80439219, 3707173.76806116],\n       [ 684289.27240227, 1032856.71531186],\n       [ 127189.61835749,  274385.59426486],\n       ...,\n       [ 630347.70469164, 1594876.58130005],\n       [ 167399.51044545,  337513.60197203],\n       [ 232815.51352497,  641580.14787679]])\n```\n\n我们还可以为每个测试样本获取完整的共形预测分布，其由阈值定义：\n\n```python\nrf.predict_cpds(X_test)\n```\n\n对于 Mondrian 共形预测系统（或任何半在线共形预测系统），输出是一个包含每个测试样本对应 CPD 的向量；而对于标准或归一化的共形预测系统（未启用在线校准），输出则是一个二维数组。\n\n此处未展示最终的向量嵌套向量结构，而是给出了一个随机测试样本的 CPD 图：\n\n![cpd](https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_readme_863320d83bb7.png)\n\n此外，我们还可以利用共形检验鞅来检验交换性假设。假设我们已经通过半在线共形预测器获得了 p 值，例如：\n\n```python\np_values = rf.predict_p(X_test, y_test, online=True)\n```\n\n现在我们可以使用 `crepes.martingales` 模块中的任意共形检验鞅算法，来检验这些 p 值是否独立且均匀地分布在 [0, 1] 区间内。如果交换性假设成立，则观察到鞅值超过 c 的概率不超过 1\u002Fc。这意味着错误拒绝该假设的概率被限制在 1\u002Fc 以内。下面演示如何使用 Simple Jumper 为上述 p 值计算鞅值：\n\n```python\nfrom crepes.martingales import SimpleJumper\n\nmartingale_values = SimpleJumper().apply(p_values)\n```\n\n我们还可以查询使鞅值超过指定阈值的最小索引：\n\n```python\nSimpleJumper().apply(np.sort(p_values), c=100)\n```\n\n由于在上述示例中 p 值已排序，共形检验鞅会较早检测到交换性假设的违反，并返回较低的索引。而如果提供的是原始（未排序）p 值，则共形检验鞅很可能无法检测到任何数据漂移，只会返回 p 值向量的长度。\n\n\n\n## 示例\n\n有关如何使用本包和模块的更多示例，请参阅 [文档](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002F)、[使用 WrapClassifier 和 WrapRegressor 的 Jupyter 笔记本](https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002Fcrepes_nb_wrap.ipynb)、[使用 ConformalClassifier、ConformalRegressor 和 ConformalPredictiveSystem 的 Jupyter 笔记本](https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002Fcrepes_nb.ipynb)，以及 [关于共形检验鞅使用的 Jupyter 笔记本](https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002Fmartingales_nb.ipynb)。\n\n您也可以查看我在 COPA 2024 大会上的教程幻灯片及其配套的 Jupyter 笔记本：\n\n[COPA 2024 教程幻灯片](\u003Chttps:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002FCOPA Tutorial 2024.pdf>) 和 [COPA 2024 教程笔记本](\u003Chttps:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fblob\u002Fmain\u002Fdocs\u002FCOPA Tutorial 2024.ipynb>)。\n\n## 引用 crepes\n\n欢迎您引用以下论文：\n\nBoström, H. 2024. 使用 crepes 在 Python 中进行共形预测。第 13 届共形与概率预测应用研讨会论文集，PMLR 230:236–249 [链接](https:\u002F\u002Fraw.githubusercontent.com\u002Fmlresearch\u002Fv230\u002Fmain\u002Fassets\u002Fbostrom24a\u002Fbostrom24a.pdf)\n\nBibTeX 条目：\n\n```bibtex\n@inproceedings{bostrom2024,\n  title={使用 crepes 在 Python 中进行共形预测},\n  author={Bostr{\\\"o}m, Henrik},\n  booktitle={第 13 届共形与概率预测应用研讨会论文集},\n  pages={236--249},\n  year={2024},\n  organization={PMLR}\n}\n```\n\n该软件包的早期版本曾在以下文献中介绍：\n\nBoström, H., 2022. crepes：用于生成共形回归器和预测系统的 Python 软件包。第 11 届共形与概率预测应用研讨会论文集，PMLR 179:24–41 [链接](https:\u002F\u002Fproceedings.mlr.press\u002Fv179\u002Fbostrom22a\u002Fbostrom22a.pdf)\n\nBibTeX 条目：\n\n```bibtex\n@inproceedings{bostrom2022,\n  title={crepes：用于生成共形回归器和预测系统的 Python 软件包},\n  author={Bostr{\\\"o}m, Henrik},\n  booktitle={第 11 届共形与概率预测应用研讨会论文集},\n  pages={24--41},\n  year={2022},\n  organization={PMLR}\n}\n```\n\n## 参考文献\n\n\u003Ca id=\"1\">[1]\u003C\u002Fa> Vovk, V., Gammerman, A. 和 Shafer, G.，2022年。随机世界中的算法学习。第二版。施普林格出版社 [链接](https:\u002F\u002Flink.springer.com\u002Fbook\u002F10.1007\u002F978-3-031-06649-8)\n\n\u003Ca id=\"2\">[2]\u003C\u002Fa> Papadopoulos, H., Proedrou, K., Vovk, V. 和 Gammerman, A.，2002年。回归的归纳置信机。欧洲机器学习会议，第345–356页。[链接](https:\u002F\u002Flink.springer.com\u002Fchapter\u002F10.1007\u002F3-540-36755-1_29)\n\n\u003Ca id=\"3\">[3]\u003C\u002Fa> Johansson, U., Boström, H., Löfström, T. 和 Linusson, H.，2014年。基于随机森林的回归共形预测。机器学习，97(1–2)，第155–176页。[链接](https:\u002F\u002Flink.springer.com\u002Farticle\u002F10.1007\u002Fs10994-014-5453-0)\n\n\u003Ca id=\"4\">[4]\u003C\u002Fa> Boström, H., Linusson, H., Löfström, T. 和 Johansson, U.，2017年。加速共形回归森林的难度估计。数学与人工智能年鉴，81(1–2)，第125–144页。[链接](https:\u002F\u002Flink.springer.com\u002Farticle\u002F10.1007\u002Fs10472-017-9539-9)\n\n\u003Ca id=\"5\">[5]\u003C\u002Fa> Boström, H. 和 Johansson, U.，2020年。蒙德里安共形回归器。载于《共形与概率预测及其应用》。PMLR，第128卷，第114–133页。[链接](https:\u002F\u002Fproceedings.mlr.press\u002Fv128\u002Fbostrom20a.html)\n\n\u003Ca id=\"6\">[6]\u003C\u002Fa> Vovk, V., Petej, I., Nouretdinov, I., Manokhin, V. 和 Gammerman, A.，2020年。共形预测分布的高效计算版本。神经计算，第397期，第292–308页。[链接](https:\u002F\u002Fwww.aminer.org\u002Fpub\u002F5e09aac9df1a9c0c416c9b70\u002Fcomputationally-efficient-versions-of-conformal-predictive-distributions)\n\n\u003Ca id=\"7\">[7]\u003C\u002Fa> Boström, H., Johansson, U. 和 Löfström, T.，2021年。蒙德里安共形预测分布。载于《共形与概率预测及其应用》。PMLR，第152卷，第24–38页。[链接](https:\u002F\u002Fproceedings.mlr.press\u002Fv152\u002Fbostrom21a.html)\n\n\u003Ca id=\"8\">[8]\u003C\u002Fa> Vovk, V.，2022年。通用预测系统。模式识别，第126卷：第108536页。[链接](https:\u002F\u002Fdl.acm.org\u002Fdoi\u002Fabs\u002F10.1016\u002Fj.patcog.2022.108536)\n\n\n- - -\n\n作者：亨里克·博斯特伦（bostromh@kth.se）\n版权所有 2025年 亨里克·博斯特伦\n许可证：BSD 3条款","# crepes 快速上手指南\n\n`crepes` 是一个用于**共形预测（Conformal Prediction）**的 Python 库。它可以将任何标准的分类器或回归器包装起来，生成具有覆盖率保证的校准 P 值、累积分布函数、预测集或预测区间。\n\n## 环境准备\n\n*   **操作系统**: Windows, macOS, Linux\n*   **Python 版本**: 建议 Python 3.8 及以上\n*   **核心依赖**:\n    *   `numpy`\n    *   `scikit-learn` (用于数据划分和基础模型)\n    *   `scipy` (部分统计功能)\n\n> **注意**：安装 `crepes` 时，上述依赖通常会自动安装。请确保已配置好基础的 Python 开发环境。\n\n## 安装步骤\n\n你可以选择通过 PyPI 或 conda-forge 进行安装。国内用户若遇到网络问题，可配置清华或阿里镜像源。\n\n### 方式一：使用 pip 安装（推荐）\n\n```bash\npip install crepes\n```\n\n**国内加速安装（使用清华源）：**\n```bash\npip install crepes -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n```\n\n### 方式二：使用 conda 安装\n\n```bash\nconda install conda-forge::crepes\n```\n\n## 基本使用\n\n以下示例展示如何使用 `crepes` 构建一个标准的共形分类器。流程分为三步：**数据划分** -> **模型训练与校准** -> **生成预测集**。\n\n### 1. 数据准备与划分\n共形预测需要将数据划分为三个部分：训练集（训练基础模型）、校准集（计算非一致性分数）和测试集。\n\n```python\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split\n\n# 加载示例数据集\ndataset = fetch_openml(name=\"qsar-biodeg\", parser=\"auto\")\nX = dataset.data.values.astype(float)\ny = dataset.target.values\n\n# 第一步：划分为训练集和测试集\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.5)\n\n# 第二步：将训练集进一步划分为“真实训练集”和“校准集”\nX_prop_train, X_cal, y_prop_train, y_cal = train_test_split(X_train, y_train,\n                                                            test_size=0.25)\n```\n\n### 2. 包装模型并校准\n使用 `WrapClassifier` 包装任意 sklearn 分类器（此处为随机森林），先在真实训练集上拟合，再在校准集上进行校准。\n\n```python\nfrom crepes import WrapClassifier\nfrom sklearn.ensemble import RandomForestClassifier\n\n# 包装随机森林分类器\nrf = WrapClassifier(RandomForestClassifier(n_jobs=-1))\n\n# 在真实训练集上训练基础模型\nrf.fit(X_prop_train, y_prop_train)\n\n# 在校准集上进行共形校准\nrf.calibrate(X_cal, y_cal)\n```\n\n### 3. 生成预测结果\n校准完成后，可以生成预测集（Prediction Sets）。以下代码生成置信度为 90% 的预测集，输出为二进制向量（1 表示包含该类，0 表示不包含）。\n\n```python\n# 生成 90% 置信水平的预测集\nprediction_sets = rf.predict_set(X_test, confidence=0.9)\n\nprint(prediction_sets[:5]) \n# 输出示例:\n# array([[0, 1],\n#        [0, 1],\n#        [1, 0],\n#        ...,\n#        [1, 0],\n#        [1, 0]])\n```\n\n你也可以直接获取校准后的 P 值：\n\n```python\np_values = rf.predict_p(X_test)\nprint(p_values[:2])\n# 输出示例:\n# array([[0.00427104, 0.74842304],\n#        [0.07874355, 0.2950549 ]])\n```\n\n> **提示**：`crepes` 同样支持回归任务（`WrapRegressor`）和更高级的 Mondrian 共形预测（针对不同类别或群体单独校准），具体用法可参考官方文档。","某制药公司的数据科学团队正在构建一个机器学习模型，用于快速筛选具有生物降解性的新分子结构，以加速环保材料的研发进程。\n\n### 没有 crepes 时\n- 模型仅输出单一的类别预测或概率值，业务部门无法判断该预测在多大程度上是可信的。\n- 面对高风险的决策场景（如是否投入昂贵的湿实验验证），缺乏统计学依据来量化预测的不确定性。\n- 传统的置信区间往往依赖严格的数据分布假设，而化学分子数据复杂多变，导致评估结果经常失真。\n- 难以向合规部门证明模型的可靠性，因为无法提供具有数学保证的覆盖率指标。\n\n### 使用 crepes 后\n- 利用共形预测技术，将原本模糊的概率转化为校准良好的 P 值和预测集合，明确告知哪些分子的分类是高度确定的。\n- 为每个预测提供带有严格覆盖率保证的区间，团队可以设定阈值，只对有统计保障的高置信度分子进行后续实验。\n- 无需假设数据服从特定分布，crepes 能自适应处理复杂的化学特征数据，生成更稳健的不确定性评估。\n- 通过 Mondrian 共形分类器，针对不同难度的分子类别分别校准，显著提升了稀有类别预测的可信度。\n\ncrepes 通过将黑盒模型的输出转化为具有数学保证的可信区间，让高风险的科研决策从“凭经验猜测”转变为“按统计行事”。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhenrikbostrom_crepes_863320d8.png","henrikbostrom","Henrik Boström","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fhenrikbostrom_2266734b.jpg",null,"KTH Royal Institute of Technology","https:\u002F\u002Fwww.kth.se\u002Fprofile\u002Fhenbos?l=en","https:\u002F\u002Fgithub.com\u002Fhenrikbostrom",[84],{"name":85,"color":86,"percentage":87},"Python","#3572A5",100,561,45,"2026-03-31T17:15:36","BSD-3-Clause",1,"","未说明",{"notes":96,"python":94,"dependencies":97},"该工具是一个基于标准分类器和回归器（如 scikit-learn）的共形预测包，主要用于生成校准后的 P 值、预测集和预测区间。安装可通过 PyPI (pip install crepes) 或 conda-forge (conda install conda-forge::crepes)。文档指出它依赖于底层模型（示例中使用了 RandomForest），自身主要依赖 numpy 和 scikit-learn。README 中未明确指定具体的 Python 版本、操作系统限制或硬件资源需求，通常意味着它适用于支持上述依赖库的标准环境。",[98,99],"scikit-learn","numpy",[13],[102,103,104,105,106,107,108,109,110,111,112,113,114,115,98,116,117],"machine-learning","conformal-prediction","conformal-regressors","conformal-predictive-systems","python","jupyter-notebook","confidence-intervals","cumulative-distribution-function","regression","sklearn","prediction-intervals","uncertainty-quantification","quantile-regression","conformal-classifiers","prediction-sets","conformal-test-martingales","2026-03-27T02:49:30.150509","2026-04-06T07:16:06.836750",[121,126,131,136,141,146],{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},12512,"在使用 ConformalPredictiveSystem 的 predict 方法时遇到 MemoryError（内存不足）怎么办？","该问题已在 v0.5.0 版本中修复。此前代码默认总是生成 'cpds' 数组导致内存占用过高，现在仅在明确请求时（设置 return_cpds=True）或在评估指标中包含 \"CRPS\" 时才会生成该数组。建议升级库版本至 0.5.0 或更高，并在不需要完整分布时避免不必要的参数调用以节省内存。","https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fissues\u002F9",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},12513,"WrapRegressor\u002FWrapClassifier 包装器是否会修改模型的 predict_proba 输出？为什么校准后有时效果不如直接在全量数据上训练？","包装器不会修改原始的 predict_proba 输出。Conformal Prediction（共形预测）的主要目的是提供具有统计保证的预测区间或集合，而非直接优化概率校准度（如 Brier Score）。如果您希望获得校准后的类别概率，Venn-Abers 预测器是更自然的选择（尽管当前包中尚未实现）。此外，如果仅使用部分训练集进行校准，其表现可能不如在全量训练集上直接拟合模型，这是符合预期的行为。","https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fissues\u002F13",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},12514,"如何在大规模数据集（如亿级行数）上提高 crepes 的扩展性和运行速度？","可以通过以下两种方式优化：\n1. **并行计算**：使用 joblib 并行化列表推导式来计算标准差。示例代码：\n   from joblib import Parallel, delayed\n   sigmas = Parallel(n_jobs=-1)(delayed(calculate_std)(indexes, y) for indexes in neighbor_indexes)\n2. **替换邻居搜索算法**：将 sklearn 的 NearestNeighbors 替换为支持 GPU 加速的 FAISS 库。可以自定义一个 FaissNearestNeighbors 类，利用 faiss.IndexFlatL2 或 faiss.IndexIVFPQ 并在 GPU 上运行，从而显著提升拟合 DifficultyEstimator 的速度。","https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fissues\u002F31",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},12515,"如何设置随机种子以确保平滑 p 值（smoothed p-values）计算的可复现性？","该功能已在 v0.7.1 版本中添加。现在您可以在初始化 WrapClassifier 或 WrapRegressor 时传递 random_state 参数（或类似的 seed 参数，具体视版本接口而定），以确保在计算平滑 p 值时的随机性是可控制的，从而保证实验结果的可复现性，特别是在处理小数据集时。","https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fissues\u002F30",{"id":142,"question_zh":143,"answer_zh":144,"source_url":145},12516,"在 Python 3.11 中调用 cps.predict 同时传入 lower_percentiles 和 higher_percentiles 时报错 ValueError 怎么办？","这是一个已知的兼容性 Bug，已在 v0.6.2 版本中修复。错误原因是代码中对空列表的判断逻辑在 Python 3.11 下表现不同。解决方案是将代码中的条件判断修改为显式检查长度，即把 `if percentile_indexes:` 改为 `if len(percentile_indexes) == 0:`。建议直接升级 crepes 库到 0.6.2 或更高版本以自动解决此问题。","https:\u002F\u002Fgithub.com\u002Fhenrikbostrom\u002Fcrepes\u002Fissues\u002F25",{"id":147,"question_zh":148,"answer_zh":149,"source_url":130},12517,"文档中的示例代码无法直接运行，缺少必要的导入语句怎么办？","文档已更新以修复此问题。在使用示例代码前，请确保手动添加以下必要的导入语句，以便代码可以直接运行：\nfrom sklearn.datasets import fetch_openml\nfrom sklearn.model_selection import train_test_split",[151,156,161,166,171,176,181,186,191,196,201,206,211,216],{"id":152,"version":153,"summary_zh":154,"released_at":155},62873,"v0.2.0","### Features\r\n\r\n- Modified `sigma_knn` to allow for calculating difficulty in three ways; using distances only, using standard deviation of the target and using the absolute residuals of the nearest neighbors.\r\n- Added `sigma_knn_oob` in `crepes.fillings`\r\n- Renamed the performance metric `efficiency` to `eff_mean` (mean efficiency) and added `eff_med` (median efficiency) to the `evaluate` method in `ConformalRegressor` and `ConformalPredictiveSystem`\r\n- Added warning messages for the case that the calibration set  is too small for the specified confidence level or lower\u002Fhigher percentiles [thanks to Geethen for highlighting this]\r\n- Added examples in comments\r\n- The documentation has been generated using Sphinx and resides in [crepes.readthedocs.io](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002F)\r\n\r\n### Fixes\r\n\r\n- Extended type checks to include NumPy floats and integers [thanks to patpizio for pointing this out]\r\n- Corrected a bug in the assignment of min\u002Fmax values for Mondrian conformal predictive systems\r\n- The Jupyter notebook with examples has been updated, changed name to `crepes_nb.ipynb` and moved to the docs folder \r\n- Changed the default `k` to 25 in `sigma_knn`\r\n","2023-04-28T08:53:25",{"id":157,"version":158,"summary_zh":159,"released_at":160},62874,"v0.1.0","## v0.1.0 (28\u002F06\u002F2022)\r\n\r\n### Feature\r\n\r\n- Added the parameter `cpds_by_bins` to the `predict` method of `ConformalPredictiveSystem`\r\n\r\n### Fixes\r\n\r\n- Comments updated and added for all classes and functions\r\n- Line widths for code and comments adjusted to meet PEP 8\r\n- Renamed some parameter names\r\n- The function `binning` in `crepes.fillings` updated to produce the correct number of bins\r\n- The Jupyter notebook `crepes.ipynb` has been updated and extended\r\n","2022-06-28T14:48:19",{"id":162,"version":163,"summary_zh":164,"released_at":165},62875,"v0.0.1","Non-production ready first release, without error handling and documentation","2021-11-17T14:43:23",{"id":167,"version":168,"summary_zh":169,"released_at":170},62862,"v0.9.0","## v0.9.0 (2025年8月10日)\n\n### 功能\n\n- 共形检验鞅已纳入新模块 `crepes.martingales`，该模块定义了投注函数 `EpsilonBettingFunction` 和 `StepBettingFunction`（带漂移和不带漂移），以及鞅 `SimpleJumper`、`SleeperStayer`、`SleeperDrifter` 和 `CompositeMartingale`。这些鞅可与任意投注函数结合使用。此外，新模块还提供了方法 `semi_online_p_values`，用于在半在线模式下从非共形性得分生成（平滑的）p值。更多详情请参阅更新后的文档及新增的 Jupyter 笔记本 `martingales_nb.ipynb`。\n\n### 修复\n\n- 修复了文档中的一个 minor bug。\n","2025-10-08T18:47:36",{"id":172,"version":173,"summary_zh":174,"released_at":175},62863,"v0.8.0","## v0.8.0 (2025年3月31日)\n\n### 功能\n\n- 新增了半在线感应式合规模型分类器、回归器和预测系统，它们在每次预测后会迭代更新校准集。对于 `WrapClassifier` 类，`predict_p`、`predict_set` 和 `evaluate` 方法现在新增了 `online` 参数，并保留了 `warm_start` 参数；其中 `online` 参数用于启用在线校准（默认关闭），而 `warm_start` 参数则允许在在线校准过程中扩展原始校准集（默认开启）。类似地，对于 `WrapRegressor` 类，`predict_p`、`predict_int`、`predict_percentiles`、`predict_cpds` 和 `evaluate` 方法也增加了 `online` 和 `warm_start` 参数。此外，所有三种类型的合规模型还新增了 `predict_p_online`（适用于 `ConformalClassifier`、`ConformalRegressor` 和 `ConformalPredictiveSystem`）、`predict_set_online`（适用于 `ConformalClassifier`）、`predict_int_online`（适用于 `ConformalRegressor` 和 `ConformalPredictiveSystem`）、`predict_percentiles_online` 以及 `predict_cpds_online` 方法，以支持半在线合规模型预测。同时，这三类合规模型的 `evaluate` 方法也新增了一个 `online` 参数，当其值为 `True` 时，将启用在线校准。\n\n- 新增了使用合规模型回归器生成平滑或非平滑 p 值的 `predict_p` 方法。\n\n- 为合规模型预测系统新增了以下方法：`predict_p` 用于获取 p 值，`predict_int` 用于获取预测区间，`predict_percentiles` 用于获取分位数，以及 `predict_cpds` 用于获取合规模型预测分布。这些输出也可以通过之前的方法 `predict`（适用于 `ConformalPredictiveSystem`）和 `predict_cps`（适用于 `WrapRegressor`）来生成。\n\n- 合规模型预测系统现在既可以输出平滑的 p 值，也可以输出非平滑的 p 值；默认采用平滑处理，但可以通过将 `predict_p` 和 `predict` 方法中的 `smoothing=False` 来禁用平滑。\n\n- `ConformalClassifier`、`ConformalRegressor`、`ConformalPredictiveSystem` 以及 `WrapClassifier` 和 `WrapRegressor` 的 `evaluate` 方法中新增了 `ks_test` 指标，该指标提供预测 p 值均匀性检验的 Kolmogorov-Smirnov 检验 p 值。感谢 @egonmedhatten 的建议！\n\n### 修复\n\n- 拟合后的对象现在包含 `fitted_` 属性，以便在 scikit-learn 流水线中得到正确处理。感谢 @lukethomrichardson 提出的修复建议。","2025-03-31T13:21:46",{"id":177,"version":178,"summary_zh":179,"released_at":180},62864,"v0.7.1","## v0.7.1 (2024年9月21日)\n\n### 功能\n\n- `WrapClassifier` 和 `WrapRegressor` 类的 `calibrate` 方法现在增加了一个额外的参数 `seed`，用于设置随机数生成器的状态。这使得前者的 `predict_p` 和 `predict_set` 方法、后者的 `predict_int` 和 `predict_cps` 方法以及两个类的 `evaluate` 方法都变为确定性方法。这些类的 `predict_p`、`predict_set`、`predict_int`、`predict_cps` 和 `evaluate` 方法也新增了 `seed` 参数，可用于覆盖 `calibrate` 方法中的设置。此外，`ConformalClassifier` 和 `ConformalPredictiveSystem` 类的相应方法同样增加了 `seed` 参数，以达到相同的目的。（目前 `ConformalRegressor` 类的方法中不包含随机成分，因此无需使用种子。）感谢 @egonmedhatten 和 @tuvelofstrom 提出这一扩展建议。\n  \n- `ConformalClassifier` 和 `WrapClassifier` 类的 `predict_p` 方法现在接受一个可选参数 `smoothing`，用于生成平滑和非平滑的 p 值（默认值为 `smoothing=True`）。\n\n- `predict_set` 和 `evaluate` 方法的 `smoothing` 参数的默认值已更改为 `True`。\n\n- `crepes.extras` 模块中的 `DifficultyEstimator` 类现在增加了一个参数 `f`，用于提供计算难度估计的函数。\n\n### 修复\n\n- 修正了 `crepes.extras` 模块中 `MondrianCategorizer` 类的文档。\n","2024-09-21T15:31:54",{"id":182,"version":183,"summary_zh":184,"released_at":185},62865,"v0.7.0","## v0.7.0 (2024年6月27日)\n\n### 功能\n\n- 在 `crepes.extras` 中新增了类 `MondrianCategorizer`，用于生成 Mondrian 一致性分类器、回归器和预测系统所使用的类别。有关该类对象通过 `fit` 和 `apply` 方法进行操作的接口，请参阅 [文档](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002Fcrepes.extras.html)。\n\n- 更新了类 `WrapRegressor` 的 `calibrate` 方法，使其能够指定一个（可选的）难度估计器和一个（可选的）Mondrian 分类器；这两个组件在校准和预测时都会被使用，而不再要求为这两项任务分别提供难度估计和 Mondrian 类别。此外，对于归一化和 Mondrian 一致性回归器及预测系统，`predict_int`、`predict_cps` 和 `evaluate` 方法不再需要显式提供 `sigmas` 和 `bins`。感谢 @tuvelofstrom 提出的相关建议。\n\n- 更新了类 `WrapClassifier` 的 `calibrate` 方法，使其能够指定一个（可选的）Mondrian 分类器；该分类器同样会在校准和预测时被使用。对于 Mondrian 一致性分类器，`predict_p`、`predict_set` 和 `evaluate` 方法也不再需要提供 `bins`。\n\t\n### 修复\n\n- 将由 pandas.Series 表示的标签向量转换为 NumPy 数组，以避免索引相关的问题。感谢 @valeman 指出这一问题。","2024-06-27T15:00:06",{"id":187,"version":188,"summary_zh":189,"released_at":190},62866,"v0.6.2","## v0.6.2 (2024年2月2日)\n\t\n### 修复\n\n- 修复了 `ConformalPredictiveSystem` 类中用于检查数组是否非空的已弃用代码。感谢 @tuvelofstrom 指出此问题。","2024-02-02T15:19:10",{"id":192,"version":193,"summary_zh":194,"released_at":195},62867,"v0.6.1","## v0.6.1 (2023年8月21日)\n\n### 功能\n\n- 在 `crepes.extras` 模块中新增了用于计算置信分类器非一致性得分的函数 `margin`。\n\n### 修复\n\n- 修复了 `DifficultyEstimator` 类（位于 `crepes.extras` 中）中的一个 bug，该 bug 会导致尝试显示未拟合对象时出现错误。感谢 @tuvelofstrom 指出此问题。\n\n- 修复了函数 `hinge` 文档中的错误。\n\n- 更新了 Jupyter 笔记本 `crepes_nb_wrap.ipynb` 和 `crepes_nb.ipynb`，以演示新的 `margin` 函数。\n","2023-08-21T07:46:11",{"id":197,"version":198,"summary_zh":199,"released_at":200},62868,"v0.6.0","## v0.6.0 (2023年6月28日)\n\n### 功能\n\n- 在 `crepes` 中新增了 `ConformalClassifier` 和 `WrapClassifier` 两个类，用于生成标准的和蒙德里安风格的共形分类器，这些分类器能够输出 p 值和预测集合。`WrapClassifier` 的 `calibrate` 方法可以方便地生成条件类别共形分类器，并支持袋外校准。有关该类对象的接口，请参阅 [文档](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002Fcrepes.html)，除了被包装的学习器原有的 `fit`、`predict` 和 `predict_proba` 方法外，还提供了 `calibrate`、`predict_p` 和 `predict_set` 方法。此外，`evaluate` 方法可用于使用一组标准指标评估预测性能。\n\n- 在 `crepes.extras` 中新增了用于计算共形分类器非一致性得分的函数 `hinge`。\n\n### 修复\n\n- 将 `Wrap` 类的名称更改为 `WrapRegressor`，并调整了该类 `calibrate` 方法的参数，使其与 `WrapClassifier` 的 `calibrate` 方法保持一致。\n\n- 更新并扩展了 Jupyter 笔记本 `crepes_nb_wrap.ipynb` 和 `crepes_nb.ipynb`。","2023-06-28T19:48:30",{"id":202,"version":203,"summary_zh":204,"released_at":205},62869,"v0.5.1","## v0.5.1（2023年6月22日）\n\n### 修复\n\n- 修复了 `ConformalPredictiveSystem` 类中 `evaluate` 方法的一个 bug，该 bug 导致在仅使用 `CRPS` 作为评估指标时（即输入 `metrics=[\"CRPS\"]`）会引发错误。感谢 @Zeeshan-Khaliq 指出此问题。\n\t\n","2023-06-22T15:09:26",{"id":207,"version":208,"summary_zh":209,"released_at":210},62870,"v0.5.0","### 功能\n\n- 只有在调用 `ConformalPredictiveSystem` 的 `predict` 方法时请求输出完整的 cpds 矩阵（即设置 `return_cpds=True`），或者在调用 `evaluate` 方法时指标集中包含 “CRPS” 时，才会计算完整的 cpds 矩阵。这样可以在其他情况下避免因测试集和校准集过大而过度占用内存。感谢 @christopherjluke 和 @SebastianLeborg 指出并讨论了这一问题。\n\n### 修复\n\n- `ConformalRegressor` 和 `ConformalPredictiveSystem` 的 `fit`、`predict` 和 `evaluate` 方法，以及 `crepes.extras` 模块中的 `binning` 函数，不再为必填参数提供默认值。\n\n- 所有分位数的 `y_min` 和 `y_max` 参数均已正确插入。\n\n- 修复了 `ConformalPredictiveSystem` 的 `evaluate` 方法，使其即使在指标中未包含 CRPS，或所有测试样本都属于同一 Mondrian 类别时，也能正常工作。\n\n- 如果分位数的取值不正确，将显示错误信息。","2023-06-02T13:19:10",{"id":212,"version":213,"summary_zh":214,"released_at":215},62871,"v0.4.0","## v0.4.0 (2023年5月16日)\n\n### 功能\n\n- 在 `crepes` 中新增了 `Wrap` 类，允许通过该类轻松地为底层学习器扩展方法，以构建并使用一致性回归模型和预测系统进行预测。有关该类对象的接口，请参阅 [文档](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002Fcrepes.html)，除了被包装学习器的 `fit` 和 `predict` 方法外，还提供了 `calibrate`、`predict_int` 和 `predict_cps` 方法。\n\n### 修复\n\n- 在文档中添加了一个 Jupyter 笔记本 `crepes_nb_wrap.ipynb`，用于演示 `Wrap` 类的用法。\n- 当一致性预测系统的输出结果数组仅包含一列时，会将其转换为向量。\n- 文档已更新，现包含指向类和方法的链接。\n- 将 `crepes.fillings` 重命名为 `crepes.extras`。\n","2023-05-16T13:38:57",{"id":217,"version":218,"summary_zh":219,"released_at":220},62872,"v0.3.0","### Features\r\n\r\n- The class `DifficultyEstimator` was added to `crepes.fillings`, incorporating functionality provided by the previous functions `sigma_knn`, `sigma_knn_oob`, `sigma_variance`, and `sigma_variance_oob`, which now are superfluous and have been removed from `crepes.fillings`. See [the documentation](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002Fcrepes.fillings.html) for the interface to objects of the class through the `fit` and `apply` methods.\r\n\r\n- An option to normalize difficulty estimates, by providing `scaler=True` to the `fit` method of `DifficultyEstimator`, has been included.\r\n\r\n### Fixes\r\n\r\n- The Jupyter notebook `crepes_nb.ipynb` has been updated to incorporate the above features\r\n\r\n- The documentation of the [crepes package](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002Fcrepes.html) and the [crepes.fillings module](https:\u002F\u002Fcrepes.readthedocs.io\u002Fen\u002Flatest\u002Fcrepes.fillings.html) has been updated with links to source code, additional examples and notes.\r\n","2023-05-11T13:09:05"]