docs: make Chinese README the default

This commit is contained in:
wehub-resource-sync
2026-07-13 10:35:03 +00:00
parent 09c3cbf62e
commit 93c51dac46
+80 -75
View File
@@ -1,151 +1,156 @@
<!-- WEHUB_ZH_README -->
> [!NOTE]
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
> [English](./README.en.md) · [原始项目](https://github.com/trekhleb/homemade-machine-learning) · [上游 README](https://github.com/trekhleb/homemade-machine-learning/blob/HEAD/README.md)
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
# Homemade Machine Learning
> 🇺🇦 UKRAINE [IS BEING ATTACKED](https://war.ukraine.ua/) BY RUSSIAN ARMY. CIVILIANS ARE GETTING KILLED. RESIDENTIAL AREAS ARE GETTING BOMBED.
> - Help Ukraine via:
> 🇺🇦 乌克兰 [正遭受攻击](https://war.ukraine.ua/),俄罗斯军队正在发动袭击。平民正在遇害,居民区正在遭受轰炸。
> - 通过以下方式援助乌克兰:
> - [Serhiy Prytula Charity Foundation](https://prytulafoundation.org/en/)
> - [Come Back Alive Charity Foundation](https://savelife.in.ua/en/donate-en/)
> - [National Bank of Ukraine](https://bank.gov.ua/en/news/all/natsionalniy-bank-vidkriv-spetsrahunok-dlya-zboru-koshtiv-na-potrebi-armiyi)
> - More info on [war.ukraine.ua](https://war.ukraine.ua/) and [MFA of Ukraine](https://twitter.com/MFA_Ukraine)
> - 更多信息请访问 [war.ukraine.ua](https://war.ukraine.ua/) [MFA of Ukraine](https://twitter.com/MFA_Ukraine)
<hr/>
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/trekhleb/homemade-machine-learning/master?filepath=notebooks)
> _Read this in other languages:_ [_Español_](README.es-ES.md)
> _其他语言版本:_ [_Español_](README.es-ES.md)
> _You might be interested in:_
> _你可能还会感兴趣:_
> - _[Homemade GPT • JS](https://github.com/trekhleb/homemade-gpt-js)_
> - _[Interactive Machine Learning Experiments](https://github.com/trekhleb/machine-learning-experiments)_
_For Octave/MatLab version of this repository please check [machine-learning-octave](https://github.com/trekhleb/machine-learning-octave) project._
_如需 Octave/MatLab 版本,请查看 [machine-learning-octave](https://github.com/trekhleb/machine-learning-octave) 项目。_
> This repository contains examples of popular machine learning algorithms implemented in **Python** with mathematics behind them being explained. Each algorithm has interactive **Jupyter Notebook** demo that allows you to play with training data, algorithms configurations and immediately see the results, charts and predictions **right in your browser**. In most cases the explanations are based on [this great machine learning course](https://www.coursera.org/learn/machine-learning) by Andrew Ng.
> 本仓库包含用 **Python** 实现的流行机器学习算法示例,并附有背后的数学原理说明。每个算法都配有交互式 **Jupyter Notebook** 演示,让你可以调整训练数据与算法配置,并立即在浏览器中查看结果、图表和预测。多数讲解基于 Andrew Ng 的 [这门优秀的机器学习课程](https://www.coursera.org/learn/machine-learning)
The purpose of this repository is _not_ to implement machine learning algorithms by using 3<sup>rd</sup> party library one-liners _but_ rather to practice implementing these algorithms from scratch and get better understanding of the mathematics behind each algorithm. That's why all algorithms implementations are called "homemade" and not intended to be used for production.
本仓库的目的 _并非_ 借助第三方库的一行代码来实现机器学习算法,_而是_ 从零开始练习实现这些算法,从而更深入理解每种算法背后的数学原理。因此,所有算法实现都称为“homemade”(自制),并不打算用于生产环境。
## Supervised Learning
## 监督学习(Supervised Learning
In supervised learning we have a set of training data as an input and a set of labels or "correct answers" for each training set as an output. Then we're training our model (machine learning algorithm parameters) to map the input to the output correctly (to do correct prediction). The ultimate purpose is to find such model parameters that will successfully continue correct _input→output_ mapping (predictions) even for new input examples.
在监督学习中,我们有一组训练数据作为输入,以及对应每组训练数据的标签或“正确答案”作为输出。随后我们训练模型(机器学习算法的参数),使其能够正确地将输入映射到输出(做出正确预测)。最终目标是找到这样的模型参数,使其即使面对新的输入样本,也能持续正确地进行 _输入→输出_ 映射(预测)。
### Regression
### 回归(Regression
In regression problems we do real value predictions. Basically we try to draw a line/plane/n-dimensional plane along the training examples.
在回归问题中,我们进行实数值预测。本质上,我们尝试沿着训练样本拟合一条直线、一个平面或 n 维超平面。
_Usage examples: stock price forecast, sales analysis, dependency of any number, etc._
_使用示例:股价预测、销售分析、任意数值之间的依赖关系等。_
#### 🤖 Linear Regression
#### 🤖 线性回归(Linear Regression
- 📗 [Math | Linear Regression](homemade/linear_regression) - theory and links for further readings
- ⚙️ [Code | Linear Regression](homemade/linear_regression/linear_regression.py) - implementation example
- ▶️ [Demo | Univariate Linear Regression](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/linear_regression/univariate_linear_regression_demo.ipynb) - predict `country happiness` score by `economy GDP`
- ▶️ [Demo | Multivariate Linear Regression](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/linear_regression/multivariate_linear_regression_demo.ipynb) - predict `country happiness` score by `economy GDP` and `freedom index`
- ▶️ [Demo | Non-linear Regression](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/linear_regression/non_linear_regression_demo.ipynb) - use linear regression with _polynomial_ and _sinusoid_ features to predict non-linear dependencies
- 📗 [Math | Linear Regression](homemade/linear_regression) - 理论与延伸阅读链接
- ⚙️ [Code | Linear Regression](homemade/linear_regression/linear_regression.py) - 实现示例
- ▶️ [Demo | Univariate Linear Regression](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/linear_regression/univariate_linear_regression_demo.ipynb) - 根据 `economy GDP` 预测 `country happiness` 分数
- ▶️ [Demo | Multivariate Linear Regression](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/linear_regression/multivariate_linear_regression_demo.ipynb) - 根据 `economy GDP` `freedom index` 预测 `country happiness` 分数
- ▶️ [Demo | Non-linear Regression](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/linear_regression/non_linear_regression_demo.ipynb) - 使用带有 _多项式__正弦_ 特征的线性回归来预测非线性依赖关系
### Classification
### 分类(Classification
In classification problems we split input examples by certain characteristic.
在分类问题中,我们根据某种特征将输入样本划分到不同类别。
_Usage examples: spam-filters, language detection, finding similar documents, handwritten letters recognition, etc._
_使用示例:垃圾邮件过滤、语言检测、查找相似文档、手写字符识别等。_
#### 🤖 Logistic Regression
#### 🤖 逻辑回归(Logistic Regression
- 📗 [Math | Logistic Regression](homemade/logistic_regression) - theory and links for further readings
- ⚙️ [Code | Logistic Regression](homemade/logistic_regression/logistic_regression.py) - implementation example
- ▶️ [Demo | Logistic Regression (Linear Boundary)](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/logistic_regression_with_linear_boundary_demo.ipynb) - predict Iris flower `class` based on `petal_length` and `petal_width`
- ▶️ [Demo | Logistic Regression (Non-Linear Boundary)](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/logistic_regression_with_non_linear_boundary_demo.ipynb) - predict microchip `validity` based on `param_1` and `param_2`
- ▶️ [Demo | Multivariate Logistic Regression | MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/multivariate_logistic_regression_demo.ipynb) - recognize handwritten digits from `28x28` pixel images
- ▶️ [Demo | Multivariate Logistic Regression | Fashion MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/multivariate_logistic_regression_fashion_demo.ipynb) - recognize clothes types from `28x28` pixel images
- 📗 [Math | Logistic Regression](homemade/logistic_regression) - 理论与延伸阅读链接
- ⚙️ [Code | Logistic Regression](homemade/logistic_regression/logistic_regression.py) - 实现示例
- ▶️ [Demo | Logistic Regression (Linear Boundary)](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/logistic_regression_with_linear_boundary_demo.ipynb) - 根据 `petal_length` `petal_width` 预测鸢尾花 `class`
- ▶️ [Demo | Logistic Regression (Non-Linear Boundary)](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/logistic_regression_with_non_linear_boundary_demo.ipynb) - 根据 `param_1` `param_2` 预测芯片 `validity`
- ▶️ [Demo | Multivariate Logistic Regression | MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/multivariate_logistic_regression_demo.ipynb) - `28x28` 像素图像中识别手写数字
- ▶️ [Demo | Multivariate Logistic Regression | Fashion MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/logistic_regression/multivariate_logistic_regression_fashion_demo.ipynb) - `28x28` 像素图像中识别服装类型
## Unsupervised Learning
## 无监督学习(Unsupervised Learning
Unsupervised learning is a branch of machine learning that learns from test data that has not been labeled, classified or categorized. Instead of responding to feedback, unsupervised learning identifies commonalities in the data and reacts based on the presence or absence of such commonalities in each new piece of data.
无监督学习是机器学习的一个分支,它从未标注、未分类或未归类的测试数据中学习。与响应反馈不同,无监督学习会识别数据中的共性,并根据每条新数据中是否存在此类共性来做出反应。
### Clustering
### 聚类(Clustering
In clustering problems we split the training examples by unknown characteristics. The algorithm itself decides what characteristic to use for splitting.
在聚类问题中,我们根据未知特征将训练样本划分到不同群组。算法本身会决定使用哪种特征进行划分。
_Usage examples: market segmentation, social networks analysis, organize computing clusters, astronomical data analysis, image compression, etc._
_使用示例:市场细分、社交网络分析、计算集群组织、天文数据分析、图像压缩等。_
#### 🤖 K-means Algorithm
#### 🤖 K-means 算法
- 📗 [Math | K-means Algorithm](homemade/k_means) - theory and links for further readings
- ⚙️ [Code | K-means Algorithm](homemade/k_means/k_means.py) - implementation example
- ▶️ [Demo | K-means Algorithm](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/k_means/k_means_demo.ipynb) - split Iris flowers into clusters based on `petal_length` and `petal_width`
- 📗 [Math | K-means Algorithm](homemade/k_means) - 理论与延伸阅读链接
- ⚙️ [Code | K-means Algorithm](homemade/k_means/k_means.py) - 实现示例
- ▶️ [Demo | K-means Algorithm](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/k_means/k_means_demo.ipynb) - 根据 `petal_length` `petal_width` 将鸢尾花划分为不同簇
### Anomaly Detection
### 异常检测(Anomaly Detection
Anomaly detection (also outlier detection) is the identification of rare items, events or observations which raise suspicions by differing significantly from the majority of the data.
异常检测(也称离群点检测)用于识别与数据中大多数样本显著不同、因而值得怀疑的罕见项、事件或观测值。
_Usage examples: intrusion detection, fraud detection, system health monitoring, removing anomalous data from the dataset etc._
_使用示例:入侵检测、欺诈检测、系统健康监控、从数据集中移除异常数据等。_
#### 🤖 Anomaly Detection using Gaussian Distribution
#### 🤖 基于高斯分布的异常检测(Anomaly Detection using Gaussian Distribution
- 📗 [Math | Anomaly Detection using Gaussian Distribution](homemade/anomaly_detection) - theory and links for further readings
- ⚙️ [Code | Anomaly Detection using Gaussian Distribution](homemade/anomaly_detection/gaussian_anomaly_detection.py) - implementation example
- ▶️ [Demo | Anomaly Detection](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/anomaly_detection/anomaly_detection_gaussian_demo.ipynb) - find anomalies in server operational parameters like `latency` and `threshold`
- 📗 [Math | Anomaly Detection using Gaussian Distribution](homemade/anomaly_detection) - 理论与延伸阅读链接
- ⚙️ [Code | Anomaly Detection using Gaussian Distribution](homemade/anomaly_detection/gaussian_anomaly_detection.py) - 实现示例
- ▶️ [Demo | Anomaly Detection](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/anomaly_detection/anomaly_detection_gaussian_demo.ipynb) - 在服务器运行参数(如 `latency` `threshold`)中查找异常
## Neural Network (NN)
## 神经网络(Neural Network, NN
The neural network itself isn't an algorithm, but rather a framework for many different machine learning algorithms to work together and process complex data inputs.
神经网络本身并非一种算法,而是一种框架,让多种不同的机器学习算法协同工作,以处理复杂的输入数据。
_Usage examples: as a substitute of all other algorithms in general, image recognition, voice recognition, image processing (applying specific style), language translation, etc._
_使用示例:总体上可替代其他各类算法、图像识别、语音识别、图像处理(应用特定风格)、语言翻译等。_
#### 🤖 Multilayer Perceptron (MLP)
#### 🤖 多层感知机(Multilayer Perceptron, MLP
- 📗 [Math | Multilayer Perceptron](homemade/neural_network) - theory and links for further readings
- ⚙️ [Code | Multilayer Perceptron](homemade/neural_network/multilayer_perceptron.py) - implementation example
- ▶️ [Demo | Multilayer Perceptron | MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/neural_network/multilayer_perceptron_demo.ipynb) - recognize handwritten digits from `28x28` pixel images
- ▶️ [Demo | Multilayer Perceptron | Fashion MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/neural_network/multilayer_perceptron_fashion_demo.ipynb) - recognize the type of clothes from `28x28` pixel images
- 📗 [Math | Multilayer Perceptron](homemade/neural_network) - 理论与延伸阅读链接
- ⚙️ [Code | Multilayer Perceptron](homemade/neural_network/multilayer_perceptron.py) - 实现示例
- ▶️ [Demo | Multilayer Perceptron | MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/neural_network/multilayer_perceptron_demo.ipynb) - `28x28` 像素图像中识别手写数字
- ▶️ [Demo | Multilayer Perceptron | Fashion MNIST](https://nbviewer.jupyter.org/github/trekhleb/homemade-machine-learning/blob/master/notebooks/neural_network/multilayer_perceptron_fashion_demo.ipynb) - `28x28` 像素图像中识别服装类型
## Machine Learning Map
## 机器学习图谱
![Machine Learning Map](images/machine-learning-map.png)
![机器学习图谱](images/machine-learning-map.png)
The source of the following machine learning topics map is [this wonderful blog post](https://vas3k.ru/blog/machine_learning/)
以下机器学习主题图谱的来源是[这篇精彩的博客文章](https://vas3k.ru/blog/machine_learning/)
## Prerequisites
## 前置要求
#### Installing Python
#### 安装 Python
Make sure that you have [Python installed](https://realpython.com/installing-python/) on your machine.
请确保你的机器上[已安装 Python](https://realpython.com/installing-python/) on your machine.
You might want to use [venv](https://docs.python.org/3/library/venv.html) standard Python library
to create virtual environments and have Python, `pip` and all dependent packages to be installed and
served from the local project directory to avoid messing with system wide packages and their
versions.
你可能想使用 [venv](https://docs.python.org/3/library/venv.html) standard Python library
来创建虚拟环境,让 Python`pip` 以及所有依赖包从本地项目目录安装并运行,
从而避免干扰系统级软件包及其版本。
#### Installing Dependencies
#### 安装依赖
Install all dependencies that are required for the project by running:
运行以下命令来安装项目所需的全部依赖:
```bash
pip install -r requirements.txt
```
#### Launching Jupyter Locally
#### 在本地启动 Jupyter
All demos in the project may be run directly in your browser without installing Jupyter locally. But if you want to launch [Jupyter Notebook](http://jupyter.org/) locally you may do it by running the following command from the root folder of the project:
项目中的所有演示都可以直接在浏览器中运行,无需在本地安装 Jupyter。但若要在本地启动 [Jupyter Notebook](http://jupyter.org/) locally you may do it by running the following command from the root folder of the project:
```bash
jupyter notebook
```
After this Jupyter Notebook will be accessible by `http://localhost:8888`.
之后,可通过 `http://localhost:8888` 访问 Jupyter Notebook。
#### Launching Jupyter Remotely
#### 远程启动 Jupyter
Each algorithm section contains demo links to [Jupyter NBViewer](http://nbviewer.jupyter.org/). This is fast online previewer for Jupyter notebooks where you may see demo code, charts and data right in your browser without installing anything locally. In case if you want to _change_ the code and _experiment_ with demo notebook you need to launch the notebook in [Binder](https://mybinder.org/). You may do it by simply clicking the _"Execute on Binder"_ link in top right corner of the NBViewer.
每个算法章节都包含指向 [Jupyter NBViewer](http://nbviewer.jupyter.org/). 的演示链接。这是一款快速的 Jupyter 笔记本(Jupyter notebooks)在线预览工具,你可以在浏览器中直接查看演示代码、图表和数据,而无需在本地安装任何内容。如果你想_修改_代码并在演示笔记本上_实验_,则需要在 [Binder](https://mybinder.org/). 中启动该笔记本。只需点击 NBViewer 右上角的 _"Execute on Binder"_ 链接即可。
![](./images/binder-button-place.png)
## Datasets
## 数据集
The list of datasets that is being used for Jupyter Notebook demos may be found in [data folder](data).
Jupyter Notebook 演示所使用的数据集列表可在 [data 文件夹](data) 中找到。
## Supporting the project
## 支持本项目
You may support this project via ❤️ [GitHub](https://github.com/sponsors/trekhleb) or ❤️ [Patreon](https://www.patreon.com/trekhleb).
你可以通过 ❤️ [GitHub](https://github.com/sponsors/trekhleb) ❤️ [Patreon](https://www.patreon.com/trekhleb). 支持本项目。
## Author
## 作者
- [@trekhleb](https://trekhleb.dev)