Chapter 1: What Is Data, Really? · 第一章:数据究竟是什么?
Chapter 1: What Is Data, Really? · 第一章:数据究竟是什么?
1.1 A Question That Sounds Easy but Isn't · 一个听起来简单却并不简单的问题
Imagine you walk into a kitchen, point at the fruit bowl on the counter, and ask: "What is an apple?" Most adults will answer without thinking — red, round, crunchy, sweet. But now try a harder question: "What is the *smell* of an apple?" Suddenly, words feel clumsy. You can describe it, but the description is never the smell itself. Data is exactly like that. It is not the thing you see, hear, or touch. It is the *recorded shadow* of the thing — a footprint pressed into a notebook, a number painted on a spreadsheet, a pattern printed into pixels. A picture of your dog is not your dog; a weight log of your dog is not your dog either. But together, those shadows can teach a machine to recognize your dog across a million strangers. That is the strange, powerful magic of data, and it is the only magic this entire book teaches you to wield.
想象一下你走进厨房,指着桌上的水果盘问:「苹果是什么?」大多数大人会不假思索地回答 —— 红色的、圆形的、脆脆的、甜甜的。但如果你换一个更难的问题:「苹果的*气味*是什么?」瞬间,语言就显得笨拙了。你可以描述它,但描述永远不是气味本身。数据正是如此。它不是你看见、听见或摸到的事物,而是该事物的*记录阴影*——按在笔记本上的脚印、用电子表格绘出的数字、或被印在像素里的图案。你家狗狗的照片不是你家的狗;狗狗的体重日志也不是你家的狗。但是,当所有这些阴影合在一起时,它们能够教会机器在百万张陌生的面孔里认出你家的狗。这正是数据的奇特而强大的魔力,也是本书将要教会你掌握的唯一魔法。
Throughout this book we treat data not as "boring numbers in a spreadsheet" but as the raw material from which intelligent systems are forged — much like iron ore is the raw material from which swords are forged. A blacksmith cannot make a sword from wishes. A data wizard cannot train an AI from wishes either. Both need a stockpile, both need a forge, and both need to know how to hammer without breaking the material. By the end of Chapter 1, you will have seen the three great families of data, the seven-step loop that turns raw observations into intelligent behavior, and a hands-on experiment you can run tonight with a notebook, a pencil, and one curious pet. Let's begin.
贯穿全书,我们会将数据视为「智能系统锻造的原料」——就像铁矿石是锻造剑刃的原料一样。铁匠无法凭愿望打造一把剑,数据巫师也无法凭愿望训练 AI。两者都需要原材料仓库,都需要熔炉,也都需要知道如何锤炼而不让材料碎裂。到本章结束时,你将看到数据的三大族群、让原始观察转化为智能行为的七步循环,外加一个今晚就能用笔记本、铅笔和一只好奇的小宠物亲手做的实验。我们开始吧。
---
1.2 Recorded Facts: The Only Definition Worth Keeping · 「记录下来的事实」——唯一值得记住的定义
The word "data" is Latin — it's the plural of *datum*, meaning "something given." In the 17th century, scientists started using it to mean *measurements given to an experiment*. By the 21st century, the word had stretched to include almost anything we could digitize: a temperature reading, a tweet, a heart-rate curve, a photograph of dust on a windowsill. With so many meanings flying around, smart practitioners compress them into one tight sentence:
> Data = a recorded fact about the world, stored in a form that a machine can read.
*数据 = 关于世界的、被记录下来的事实,以机器可读的形式存储。*
Why "recorded"? Because nothing you merely *think* is data. A child who knows "it feels cold today" has only an opinion; the moment the child writes down *-3 °C at 9:00 a.m.*, an opinion becomes data. The act of recording turns a private experience into a public, shareable, checkable artifact. Why "fact"? Because data is supposed to describe something that *actually happened* at *some particular time and place*. A guess — even a very confident one — is not data; it becomes data only when it is checked against reality. And why "machine-readable"? Because the systems we will build do not sip tea and listen to stories. They need their facts delivered in symbols they can parse: bits, bytes, characters, numbers, pixels, samples.
为什么必须是「记录的」?因为仅仅*想到*的东西不是数据。一个孩子知道「今天感觉很冷」只是一种感觉;当他写下「上午 9 点零下 3 摄氏度」时,感觉就变成了数据。记录这个动作,把私人体验变成了可共享、可公开检验的产物。为什么必须是「事实」?因为数据应当描述*真正发生过*的事情——发生在*某个特定时间和地点*的事情。一个猜测——哪怕是非常自信的猜测——也不是数据;它只有在被现实检验之后才能成为数据。为什么必须是「机器可读」?因为我们将构建的系统不会端着茶杯听故事。它们需要可以解析的符号:比特、字节、字符、数字、像素、采样。
Now here is a subtle but critical twist that will echo through every page of this book: a single fact, by itself, is almost useless. One temperature reading tells you the weather at one moment for one place. A *collection* of facts, however, lets you see a pattern: temperatures rise each afternoon, fall at night, peak in July. The leap from single facts to patterns is where statistics begins; the leap from patterns to predictions is where machine learning begins; and the leap from predictions to decisions is where AI begins. Every wizard you'll meet in the following chapters — every data engineer, every annotation lead, every model trainer — is in the business of turning *facts* into *patterns* into *predictions* into *decisions*. That is the whole craft.
现在有一个微妙却关键的转折,将会在本书每一页反复出现:单独一条事实本身几乎没什么用。一次温度读数只能告诉你某地某刻的天气。但当多个事实*汇聚在一起*时,你就能看到规律:下午气温上升、夜晚下降、七月份达到顶峰。从「单条事实」到「规律」的跨越,是统计学的起点;从「规律」到「预测」的跨越,是机器学习的起点;从「预测」到「决策」的跨越,是 AI 的起点。本书接下来你会遇到的每一位「巫师」——每一位数据工程师、每一位标注组长、每一位模型训练师——他们从事的事业,都是把*事实*转化为*规律*,再转化为*预测*,再转化为*决策*。这就是整门手艺。
1.2.1 Signal vs. Noise: Why Most Recorded Facts Are Wrong · 信号与噪声:为什么大多数记录下来的事实都有偏差
Every dataset, no matter how carefully collected, contains two kinds of entries: signals (information that reflects the truth) and noise (errors, accidents, lies, glitches). A bathroom scale that reads 12.5 kg when your cat is actually 4 kg is producing noise. A heart-rate monitor that skips a beat during a sneeze is producing noise. A weather station next to a hot asphalt parking lot is producing systematically *high* temperatures — still a fact, still recorded, still machine-readable, but biased. A wise wizard does not despair at this — noise is unavoidable — but she does three things: (1) measure how much noise is in the data, (2) reduce it when possible, and (3) make the AI robust to it when not possible. We will return to noise again and again in this book, especially in Chapter 4 (cleaning) and Chapter 9 (synthetic data as a noise dial).
每个数据集,无论采集多么用心,都包含两类条目:信号(反映事实的信息)与噪声(错误、意外、谎言、故障)。当你的猫实际重 4 公斤时,体脂秤显示 12.5 公斤——这就是噪声。心率监测器在打喷嚏时漏掉一拍——这也是噪声。设在沥青停车场旁的气象站读出的温度持续偏高——它仍然是事实,仍被记录了下来,仍可被机器读取,但它有偏差。聪明的巫师不会因此绝望——噪声不可避免——但她会做三件事:(1) 测量数据中包含多少噪声;(2) 在可能时降低噪声;(3) 在无法消除时让 AI 对噪声具有鲁棒性。我们将在本书反复回到噪声话题,特别是在第 4 章(数据清洗)和第 9 章(作为噪声旋钮的合成数据)中。
---
1.3 The Three Families of Data · 数据的三大族群
Every fact a wizard records falls into one of three broad families. They behave differently, store differently, and demand different tools. Conflating them is one of the most common beginner mistakes — and one of the most costly. Let's meet each family in turn.
巫师记录的每一条事实都属于三大族群之一。它们的特性不同、存储方式不同、所需的工具也不同。把它们混为一谈,是初学者最常见也代价最大的错误之一。下面我们逐一认识。
1.3.1 Structured Data: When Everything Lines Up · 结构化数据:一切整齐排列
Structured data is what most people picture when they hear the word "data." It lives in tables: rows and columns, like a chessboard with information as the pieces. Each row is one *example* (one observation, one record, one patient, one transaction). Each column is one *attribute* (one feature, one measurement, one property). The strict grid lets computers search, sort, and compute with blinding speed — databases were literally invented to manage structured data.
结构化数据是多数人听到「数据」一词时脑中浮现的样子。它居住在表格里:行与列,就像摆满信息的棋盘。每一行是一个*样本*(一个观察、一个记录、一个病人、一笔交易);每一列是一个*属性*(一个特征、一个测量、一个属性)。严格的网格让计算机可以以惊人的速度检索、排序和计算——数据库正是为了管理结构化数据而发明的。
```python
A tiny structured dataset: a week of cat activity
import csv
rows = [ ["date", "sleep_hours", "play_minutes", "food_grams"], ["2025-03-01", 14.0, 25, 60], ["2025-03-02", 13.5, 30, 65], ["2025-03-03", 15.0, 15, 60], ["2025-03-04", 14.0, 45, 70], ["2025-03-05", 13.0, 50, 70], ["2025-03-06", 16.0, 10, 55], ["2025-03-07", 14.5, 35, 65], ]
with open("cat_log.csv", "w", newline="") as f: writer = csv.writer(f) writer.writerows(rows)
print("Saved cat_log.csv with 7 rows of structured data.") ```
The output above is exactly the kind of file you'll meet in real engineering. Notice four things: a head