# 附录 E：工程师配套实验代码

本附录目录包含《零基础学 AI》的技术实践配套实验。对于有编程基础、想要从“概念理解”跨跃到“工程落地”的读者，本目录提供了最小可运行的代码示例，帮助构建可复现的工程闭环。

> \[!NOTE] **声明与版本说明**
>
> * 以下代码主要设计用于展示概念与最小可行解，而非企业生产环境的直接拷贝。
> * 本项目推荐的运行环境（截至 2026-05 的基准环境）：
>   * **Python**: 3.14
>   * **PyTorch**: 2.11
>   * 当前实验不依赖 Transformers；后续新增大模型推理实验时，再按官方兼容矩阵补充。
> * 如果使用旧版本或更新的版本，可能会遇到部分 API 废弃或变更的情况，请参考官方文档。

## 实验清单

1. `01_ml_basics.py`: 机器学习基础指标闭环（对应第 4 章：监督学习）。涵盖数据划分、模型拟合、指标评估。**可运行**。
2. `02_structured_output.py`: 本地 JSON Schema 校验（对应第 12.2 节：结构化输出）。展示如何超越“Markdown 输出提示词”，实现严格的代码级约束。**可运行**。
3. `03_dl_overfitting.py`: 深度学习的过拟合与早停机制可观测实验（对应第 5 章）。**可运行**。
4. `04_rag_minimal.py`: 最小 RAG（检索增强生成）流程（对应第 12.5 节：上下文工程）。**可运行**：使用本地小语料、TF-IDF 检索和抽取式回答展示完整闭环。
5. `05_agent_evals.py`: 智能体输出的一致性、相关性与上下文忠实度评测（对应第 14 章：AI 智能体）。**可运行**：使用本地词汇重叠指标展示 Evals 基本流程。

### 环境安装建议

建议使用 `virtualenv` 或 `conda` 创建独立的 Python 3.14+ 环境后安装依赖。

```bash
# 在仓库根目录运行
pip install -r labs/requirements.txt
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/ai_beginner_guide/fu-lu/labs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
