# scikit-learn

**scikit-learn** 是一个面向 Python 的开源机器学习库，支持监督学习与无监督学习，并提供模型拟合、数据预处理、模型选择与模型评估等工具。<sup>[1](https://scikit-learn.org/1.8/getting_started.html)</sup> 它构建于 SciPy 之上，以三条款 BSD 许可证分发，整合了面向中等规模问题的大量经典机器学习算法，旨在让非专业人士也能用上机器学习。<sup>[2](https://github.com/scikit-learn/scikit-learn)</sup><sup> • </sup><sup>[3](https://jmlr.csail.mit.edu/papers/volume12/pedregosa11a/pedregosa11a.pdf)</sup> 一份关于 Python 机器学习生态的综述称其为小到中等规模数据集上进行特征工程与经典机器学习的行业标准，其中“小”指样本少于 1,000 例，“中等”指 1,000 至 100,000 例。<sup>[4](https://www.mdpi.com/2078-2489/11/4/193)</sup>

| 关键事实 | 详情 |
|---|---|
| 许可证与基础 | 三条款 BSD 许可证；构建于 SciPy 之上的 Python 模块，由志愿者团队维护<sup>[2](https://github.com/scikit-learn/scikit-learn)</sup> |
| 核心 API | API 由三个互补的接口构成：估计器（fit）、预测器（predict）与转换器（transform）；其设计围绕以 NumPy 数组或 SciPy 稀疏矩阵表示的数据集展开<sup>[5](https://dtai.cs.kuleuven.be/events/lml2013/papers/lml2013_api_sklearn.pdf)</sup> |
| 历史 | 2007 年由达维德·库尔诺波（David Cournapeau）作为谷歌编程之夏项目启动；2010 年 2 月 1 日由法国国家信息与自动化研究所（INRIA）的团队首次公开发布<sup>[6](https://scikit-learn.org/stable/about.html)</sup> |
| 有意排除 | 深度学习与强化学习不在范围内；不含卷积层与注意力层，但提供基础的多层感知机<sup>[7](https://sklearn.org/stable/faq.html)</sup><sup> • </sup><sup>[8](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)</sup> |
| 规模限制 | 仅有少数算法通过 joblib 并行化；规模受限于单台机器的内存与物理核心数<sup>[4](https://www.mdpi.com/2078-2489/11/4/193)</sup> |
| 采用情况 | 最近一个月 PyPI 下载量 184,326,320 次；最新版本 1.9.1<sup>[9](https://pypistats.org/packages/scikit-learn)</sup> |
| 2023 年后的方向 | 实验性的数组 API 支持让越来越多的估计器可在 GPU 上运行，输入为 PyTorch 或 CuPy 数组；截至 Probabl 的 GPU 访谈，已有 25 个估计器完成更新<sup>[7](https://sklearn.org/stable/faq.html)</sup><sup> • </sup><sup>[10](https://blog.probabl.ai/scikit-learn-acceleration-with-gpus-andy-terrel)</sup> |

## 历史与治理

该项目于 2007 年由达维德·库尔诺波作为谷歌编程之夏（Google Summer of Code）项目启动，马蒂厄·布鲁谢（Matthieu Brucher）同年因其学位论文开始参与其中。<sup>[6](https://scikit-learn.org/stable/about.html)</sup> 项目联合创始人加埃尔·瓦罗夸（Gaël Varoquaux）的一篇回顾文章记载，代码一度日渐萎缩，直到 2010 年 INRIA 的 Parietal 团队接手该项目并聘请了一名全职工程师；高效的 LibSVM 绑定为项目带来了有力的早期优势。<sup>[11](https://amueller.github.io/papers/wo_the_machine_varoquaux.pdf)</sup>

2010 年，INRIA 的法比安·佩德雷戈萨（Fabian Pedregosa）、加埃尔·瓦罗夸、亚历山大·格拉姆福尔（Alexandre Gramfort）与樊尚·米歇尔（Vincent Michel）接过领导工作，并于 2010 年 2 月 1 日发布首个公开版本；此后发布周期约为三个月一次。<sup>[6](https://scikit-learn.org/stable/about.html)</sup> INRIA 持有其雇员在贡献当时所完成工作的版权，并资助了法比安·佩德雷戈萨（2010—2012）、雅克·格罗布勒（Jaques Grobler，2012—2013）与奥利维耶·格里泽尔（Olivier Grisel，2013—2017）的全职工作。<sup>[6](https://scikit-learn.org/stable/about.html)</sup> 项目自称由社区驱动，机构与私人资助帮助确保其可持续性。<sup>[6](https://scikit-learn.org/stable/about.html)</sup> 也有公司资助开发者；例如安德烈亚斯·米勒（Andreas Müller）在 scikit-learn 上的工作由纽约大学（NYU）提供支持。<sup>[12](https://datatalks.club/podcast/open-source-ml-tools-strategy-and-business-models.html)</sup> 2024 年从 INRIA 分拆出来的公司 Probabl 雇用了数位核心维护者。<sup>[8](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)</sup>

维护活动依然可观。自 2020 年 1 月 1 日以来，共新开 4,909 个议题，其中 3,889 个（79%）已关闭，93% 的议题在 24 小时内获得评论。<sup>[13](https://devstats.scientific-python.org/_generated/scikit-learn/)</sup> 截至 2025 年 7 月 3 日，项目平均每月新增 16 名提交者，每月活跃提交者共 38 名，每月 96 次提交，累计合并或关闭的拉取请求达 18,336 个。<sup>[14](https://git-pulse.github.io/snapshots/scikit-learn-scikit-learn-2025-07-03-pulse.html)</sup>

## 设计与 API

scikit-learn 的每个对象都遵循同一套核心 API，它围绕三个互补的接口构建：估计器，用于构建并拟合模型；预测器，用于生成预测；转换器，用于变换数据。<sup>[5](https://dtai.cs.kuleuven.be/events/lml2013/papers/lml2013_api_sklearn.pdf)</sup> 核心对象是估计器，它实现 fit 方法，接受输入数据数组，在有监督问题中还可选择接受标签数组；有监督估计器实现 predict，而 PCA 之类的转换器实现 transform。<sup>[3](https://jmlr.csail.mit.edu/papers/volume12/pedregosa11a/pedregosa11a.pdf)</sup>

**接口优先于继承。** 代码对象以接口而非继承来规定，因此外部对象无需继承 scikit-learn 的类即可互操作。<sup>[3](https://jmlr.csail.mit.edu/papers/volume12/pedregosa11a/pedregosa11a.pdf)</sup> 设计原则包括一致性、可检视性（参数以公开属性暴露）、不滥增类，以及将数据集表示为 NumPy 数组或 SciPy 稀疏矩阵。<sup>[5](https://dtai.cs.kuleuven.be/events/lml2013/papers/lml2013_api_sklearn.pdf)</sup> 估计器还实现 get_params 与 set_params，网格搜索会用到它们。<sup>[1](https://scikit-learn.org/1.8/getting_started.html)</sup>

由于估计器遵循共同的 API，管道、交叉验证与网格搜索可以统一地作用于相互兼容的估计器与转换器。<sup>[8](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)</sup> scikit-learn 首创的 fit()/predict() 模式，已成为许多其他库的灵感来源与蓝图。<sup>[4](https://www.mdpi.com/2078-2489/11/4/193)</sup>

**管道与泄漏。** 预处理器与转换器遵循同样的估计器 API，只是以 transform 方法代替 predict。<sup>[1](https://scikit-learn.org/1.8/getting_started.html)</sup> 转换器与估计器可组合成管道（Pipeline），有助于防止数据泄漏，即部分测试数据出现在训练数据之中：若在交叉验证之前对整个数据集施加预处理步骤，训练数据与测试数据相互独立这一基本假设便遭到破坏。<sup>[1](https://scikit-learn.org/1.8/getting_started.html)</sup> scikit-learn 提供交叉验证与超参数调优工具，如 RandomizedSearchCV；在整个管道而非单个估计器上搜索，有助于避免预处理带来的泄漏。<sup>[1](https://scikit-learn.org/1.8/getting_started.html)</sup>

## 特性、算法与有意排除

scikit-learn 涵盖线性模型、树与集成方法、支持向量机、聚类、分解，以及一个基础的多层感知机；卷积、注意力及其他深度学习层不在其范围内。<sup>[8](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)</sup> 项目的常见问题解答指出，深度学习与强化学习不属于 scikit-learn 力求达成的目标范围，因为它们需要丰富的架构词汇，而深度学习还需要 GPU，这与项目的设计约束不符。<sup>[7](https://sklearn.org/stable/faq.html)</sup>

项目有意偏向久经考验的算法，并在默认参数的选择上极为审慎；它的设计目标是运行在任何支持科学 Python 技术栈的平台上，而非 GPU 或移动平台。<sup>[11](https://amueller.github.io/papers/wo_the_machine_varoquaux.pdf)</sup> 维护者会权衡每项新特性与其维护成本，因为不受控的增长会拖慢项目；到 2015 年，项目已在全球拥有 200 多名贡献者。<sup>[11](https://amueller.github.io/papers/wo_the_machine_varoquaux.pdf)</sup>

## 实现与性能限制

scikit-learn 是构建于 SciPy 之上的 Python 模块。<sup>[2](https://github.com/scikit-learn/scikit-learn)</sup> 其必需依赖为 joblib、narwhals、numpy、scipy 与 threadpoolctl；当前要求 Python 3.11 或更高版本、NumPy 1.24.1 或更高版本、SciPy 1.10.0 或更高版本。<sup>[9](https://pypistats.org/packages/scikit-learn)</sup><sup> • </sup><sup>[2](https://github.com/scikit-learn/scikit-learn)</sup> 基于树的模型以 Cython 实现，常见问题解答指出，它们从根本上不是基于数组的算法，因此无法高效利用数组 API，而 Cython 的核融合改写也无法通过该 API 表达。<sup>[7](https://sklearn.org/stable/faq.html)</sup>

该库在 CPU 上运行，数据驻留内存，建立在 NumPy 与 SciPy 之上，适合能装进单台机器的数据集；若要训练深度神经网络或在 GPU 上训练，用户会将其与深度学习框架搭配使用。<sup>[8](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)</sup> 只有少数 scikit-learn 算法利用 joblib 进行并行执行，这些算法能扩展到何种程度，受限于单台机器的内存与可用物理核心数。<sup>[4](https://www.mdpi.com/2078-2489/11/4/193)</sup>

## 与其他方案的比较

2023 年一项针对 scikit-learn、TensorFlow、PyTorch 与 XGBoost 的对比基准测试发现，scikit-learn 在传统机器学习任务的简洁性与易用性上表现突出，TensorFlow 与 PyTorch 在深度学习应用中性能更优，XGBoost 在梯度提升任务中效率惊人。<sup>[15](https://wjarr.com/sites/default/files/fulltext_pdf/WJARR-2023-2144.pdf)</sup> 2025 年发表的一篇基准测试预印本得出相同结论：对于计算密集型负载，PyTorch 是首选框架，而 scikit-learn 更适合较轻、要求不高的任务；在该研究中，PyTorch 与 Keras/TensorFlow 在前馈神经网络分类上表现最佳，scikit-learn 则落在后面。<sup>[16](https://www.biorxiv.org/content/10.1101/2025.02.02.635632v1)</sup>

实际的分工源于实现方式：scikit-learn 适合能装进单台机器的经典表格型负载，而当需要 GPU 训练或大型神经架构时，则由深度学习框架接手。<sup>[8](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)</sup>

## 采用与实际使用

下载量显示了使用规模：在 PyPI 上，scikit-learn 最近一日下载 4,783,374 次，最近一周 44,715,270 次，最近一月 184,326,320 次，最新版本为 1.9.1。<sup>[9](https://pypistats.org/packages/scikit-learn)</sup>

典型工作流依循 API 的形态。用户将预处理与模型组合成管道，用 RandomizedSearchCV 之类的工具在整个管道上调优超参数，并以交叉验证进行评估，这样预处理被限制在每一折内部，从而防止泄漏。<sup>[1](https://scikit-learn.org/1.8/getting_started.html)</sup> 训练好的模型用 pickle 或 joblib 保存，导出 ONNX 则需要另用 skl2onnx 项目。<sup>[8](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)</sup>

## 近期进展

**数组 API 与 GPU。** 自 2023 年起，通过实验性的数组 API 支持，若输入数据以 PyTorch 或 CuPy 数组提供，数量有限但不断增多的 scikit-learn 估计器便可在 GPU 上运行。<sup>[7](https://sklearn.org/stable/faq.html)</sup> 这项 GPU 工作通过数组 API 重新改造 scikit-learn，使其与后端无关，参与者包括 Probabl、昆赛特（Quansight）与英伟达（NVIDIA）；截至 Probabl 的访谈，已有 25 个估计器及评分 API 等核心工具为符合数组 API 而更新，并通过跨硬件后端的自动化测试加以验证。<sup>[10](https://blog.probabl.ai/scikit-learn-acceleration-with-gpus-andy-terrel)</sup> 核心维护者奥利维耶·格里泽尔展示了将计算密集的步骤卸载到 GPU 后，复杂机器学习管道获得 15 倍加速。<sup>[10](https://blog.probabl.ai/scikit-learn-acceleration-with-gpus-andy-terrel)</sup>

**元数据路由。** 元数据路由将 sample_weight、groups 之类的元数据经由管道传递给使用它们的对象；它仍属实验性，但被形容为在实践中已趋成熟，其采用正在生态系统中扩散，例如 fairlearn、imbalanced-learn、skada、skorch 与 skfolio。<sup>[17](https://blog.probabl.ai/update-on-scikit-learn-metadata-routing-api)</sup> 管道的 transform_input 参数于 1.6 版引入，允许用户定义应随 X 一同变换、直到某一步骤将其消费的元数据；这防止了 HistGradientBoostingClassifier 内部早停划分造成的泄漏。LightGBM 估计器与该 API 兼容，而撰写之时 XGBoost 尚不支持 transform_input。<sup>[17](https://blog.probabl.ai/update-on-scikit-learn-metadata-routing-api)</sup>

## 反响、批评与陷阱

项目要求科学出版物引用佩德雷戈萨等发表于《机器学习研究杂志》（JMLR）第 12 卷、第 2825—2830 页（2011 年）的论文，即介绍该库的那篇同行评审论文。<sup>[6](https://scikit-learn.org/stable/about.html)</sup><sup> • </sup><sup>[3](https://jmlr.csail.mit.edu/papers/volume12/pedregosa11a/pedregosa11a.pdf)</sup>

有据可查的主要陷阱是预处理中的数据泄漏。在交叉验证之前对整个数据集施加预处理步骤，会破坏训练数据与测试数据之间的独立性假设；使用管道可将预处理限制在交叉验证内部，从而防止泄漏。<sup>[1](https://scikit-learn.org/1.8/getting_started.html)</sup> 更隐蔽的一种情形出现在执行内部验证划分的模型中：若无 transform_input，用于早停的验证集可能无法与训练数据保持一致变换，而 1.6 版的该参数正是为解决此问题。<sup>[17](https://blog.probabl.ai/update-on-scikit-learn-metadata-routing-api)</sup>

在可持续性方面，项目自身的材料称其由社区驱动，机构与私人资助帮助确保其延续，<sup>[6](https://scikit-learn.org/stable/about.html)</sup> 而联合创始人的回顾文章则将维护成本视为增长的硬约束：每项新特性都伴随维护成本，不受控的增长会让项目不断增重，直至寸步难行。<sup>[11](https://amueller.github.io/papers/wo_the_machine_varoquaux.pdf)</sup> GPU 与数组 API 工作的方向仍在推进之中，基于树的 Cython 实现因从根本上不是基于数组的算法，无法高效利用数组 API。<sup>[7](https://sklearn.org/stable/faq.html)</sup><sup> • </sup><sup>[10](https://blog.probabl.ai/scikit-learn-acceleration-with-gpus-andy-terrel)</sup>

## References

1. [Getting Started — scikit-learn 1.8.0 documentation](https://scikit-learn.org/1.8/getting_started.html)
2. [scikit-learn: machine learning in Python (official GitHub repository)](https://github.com/scikit-learn/scikit-learn)
3. [Scikit-learn: Machine Learning in Python (Pedregosa et al., JMLR 12, 2011)](https://jmlr.csail.mit.edu/papers/volume12/pedregosa11a/pedregosa11a.pdf)
4. [Machine Learning in Python: Main Developments and Technology Trends (Information, 2020)](https://www.mdpi.com/2078-2489/11/4/193)
5. [API design for machine learning software: experiences from the scikit-learn project (Buitinck et al., 2013)](https://dtai.cs.kuleuven.be/events/lml2013/papers/lml2013_api_sklearn.pdf)
6. [About us — scikit-learn documentation](https://scikit-learn.org/stable/about.html)
7. [Frequently Asked Questions — scikit-learn 1.9.0 documentation](https://sklearn.org/stable/faq.html)
8. [PyTorch vs scikit-learn: Machine Learning Frameworks and Libraries Comparison (faun.dev)](https://faun.dev/toolbox/pytorch-vs-scikit-learn/)
9. [PyPI Download Stats — scikit-learn](https://pypistats.org/packages/scikit-learn)
10. [Scikit-learn acceleration with GPUs: A conversation with Dr. Andy Terrel (Probabl)](https://blog.probabl.ai/scikit-learn-acceleration-with-gpus-andy-terrel)
11. [Scikit-learn: (wo)the machine (Varoquaux, GetMobile 2015)](https://amueller.github.io/papers/wo_the_machine_varoquaux.pdf)
12. [Open Source ML Tools: Scikit-Learn Governance, Sustainability and Business Models — DataTalks.Club](https://datatalks.club/podcast/open-source-ml-tools-strategy-and-business-models.html)
13. [scikit-learn — Scientific Python Developer Statistics](https://devstats.scientific-python.org/_generated/scikit-learn/)
14. [scikit-learn/scikit-learn — pulse snapshot for 03 July 2025](https://git-pulse.github.io/snapshots/scikit-learn-scikit-learn-2025-07-03-pulse.html)
15. [Machine learning implementation in Python: Performance analysis of different libraries (WJARR, 2023)](https://wjarr.com/sites/default/files/fulltext_pdf/WJARR-2023-2144.pdf)
16. [Comparative Analysis of Machine Learning Libraries for Neural Networks: A Benchmarking Study (bioRxiv, 2025)](https://www.biorxiv.org/content/10.1101/2025.02.02.635632v1)
17. [Update on scikit-learn's Metadata Routing API (Probabl)](https://blog.probabl.ai/update-on-scikit-learn-metadata-routing-api)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Applied, official, and domain statistics › Computational statistics › Computational statistical learning

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/scikit-learn

English original: https://www.edgepedia.org/scikit-learn
